Question about GET and POST vars...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
_mike_
Forum Newbie
Posts: 4
Joined: Fri Jul 29, 2005 3:38 pm
Location: Somewhere on this planet

Question about GET and POST vars...

Post by _mike_ »

Hello, I have looked, but haven't been able to find a coherent answer on my question anywhere, so I ask ik here, in the hope any of you know an answer to my question.

Here it goes,

I know there is the $_GET and the $_POST vars to get the values... my question is, is there a global var that includes the values from both $_GET and $_POST? because my website has $_POST and $_GET variables to access several pages on the same way, and I'd hate to have to double code all the if statements.

Already thanks for your time,

Michael
_mike_
Forum Newbie
Posts: 4
Joined: Fri Jul 29, 2005 3:38 pm
Location: Somewhere on this planet

Post by _mike_ »

Never mind, I've built my own solution, thanks anyways if you've thought about it.

Michael

Code: Select all

function getvar($name)
	{
	if(IsSet($_GETї$name]))
		{
		$ret = $_GETї$name];
		}
	if(IsSet($_POSTї$name]))
		{
		$ret = $_POSTї$name];
		}
	return $ret;
	}
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Yes there is. $_REQUEST contains the outputs of $_GET, $_POST and $_COOKIE
_mike_
Forum Newbie
Posts: 4
Joined: Fri Jul 29, 2005 3:38 pm
Location: Somewhere on this planet

Post by _mike_ »

mmm, thanks, I thought of another way though... delved a bit into the phpbb code to figure out hehe.

Code: Select all

$_VAR = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);
Then I have everything I need in one.

Thanks for your help anyways.

Michael
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Hmm... you don't seem to understand exactly how superglobals work...

http://us2.php.net/manual/en/language.v ... perglobals

Your code should be:

Code: Select all

$_VAR = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_SESSION, $_ENV, $_FILES);
But I don't think it does exactly what you want it to (once again, read the link above)

Once again, $_REQUEST is the same as merging GET POST and COOKIE but without the overhead of calling a function, so it's faster.

Just because it works doesn't mean it's the best solution.
_mike_
Forum Newbie
Posts: 4
Joined: Fri Jul 29, 2005 3:38 pm
Location: Somewhere on this planet

Post by _mike_ »

true, but thing is, my page is merged with the phpbb code, and I really don't wish to learn the phpbb code from my head, to know what does what, and my solution works atm, I took it from the phpbb code directly...
It works, my site is secure, I'm happy ;)

Thanks though for your replies

Michael
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

LOL. phpbb and secure in one sentence.
Post Reply