MyBB Community Forums

Full Version: $mybb->input returning null?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I am creating a custom page, and for some reason when I try to return $mybb->input["cid"} it returns as null or 0.

However if I try to return $_GET["cid"] it returns with the correct value.

THis is on a custom page


<?php 
define('IN_MYBB', 1); 
require("global.php");


echo "input: ".$mybb->input["cid"];

echo "<br/>input $_GET: " $_GET["cid"];

?>


THere is a whole lot of other stuff on my page but if I just narrow down to that is doesnt work.

Other things like $lang $templates, $db and $mybb->user all seem to work however.

Can anyone think of any reason for this?

Ok for some reason I am guessing because it had "id" in the variable it was looking at cid as an int rather than a string and sanitizing it.

If I change the rewrite rule to con= all is sweet.

Useful info to know
Odd, it should work.
Did you declare the global $mybb?
He's saying $mybb->user and such variables are working, so I believe he did.
This might be issue in the code from where this cid thing is getting. Please paste the complete code you're using other then the one pasted above.
(2012-10-26, 07:19 AM)Dannymh Wrote: [ -> ]Ok for some reason I am guessing because it had "id" in the variable it was looking at cid as an int rather than a string and sanitizing it.

If I change the rewrite rule to con= all is sweet.

Useful info to know

That is because the "cid" input key is sanitized in class_core.php:

	/**
	 * Variables that need to be clean.
	 *
	 * @var array
	 */
	public $clean_variables = array(
		"int" => array(
			"tid", "pid", "uid",
			"eid", "pmid", "fid",
			"aid", "rid", "sid",
			"vid", "cid", "bid",
			"pid", "gid", "mid",
			"wid", "lid", "iid",
			"sid"),
		"a-z" => array(
			"sortby", "order"
		)
	);
/*~~~~~~~~~~~~~~~~~~~~~~~~*/
	/**
	 * Cleans predefined input variables.
	 *
	 */
	function clean_input()
	{
		foreach($this->clean_variables as $type => $variables)
		{
			foreach($variables as $var)
			{
				// If this variable is in the ignored array, skip and move to next.
				if(in_array($var, $this->ignore_clean_variables))
				{
					continue;
				}

				if(isset($this->input[$var]))
				{
					if($type == "int" && $this->input[$var] != "lastposter")
					{
						$this->input[$var] = intval($this->input[$var]);
					}
					else if($type == "a-z")
					{
						$this->input[$var] = preg_replace("#[^a-z\.\-_]#i", "", $this->input[$var]);
					}
				}
			}
		}
	}
Very good info I'm going to take a deeper look to see what else is sanitized.

In this case the variable I am looking for can be either an iD or a string
Can you post the whole code?
You will need to use a different key then ('con' will work).
Yup went with a different key. Can't post while code yet, it's just part of the content delivery system