how does $_GET, $_POST, $_REQUEST works?

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
savior14
Forum Newbie
Posts: 2
Joined: Thu Mar 04, 2010 12:46 am

how does $_GET, $_POST, $_REQUEST works?

Post by savior14 »

newby here. Feel free to transfer this post if this is not the right place :)

im just curious on how it works.

does this function uses substring function to get the specific value of a url querystring?

what is better or is it the same?

Code: Select all

if(isset($_GET['id']))
{
 if($_GET['id'] == '00000')
{
}
else if($_GET['id'] == '99999')
{
}
}

Code: Select all

$id = $_GET['id'];
if(isset($id))
{
 if($id == '00000')
{
}
else if($id == '99999')
{
}
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how does $_GET, $_POST, $_REQUEST works?

Post by requinix »

They aren't functions. Not sure why people think that because it's completely wrong.
PHP can see the query string and parses it for $_GET. PHP can also see if there was anything posted to the script and parses that for $_POST. $_REQUEST is generally some combination of $_GET, $_POST, and $_COOKIE.
Exactly how it does that I don't know, and I'm not inclined to check the source code to find out.

The only difference between the first and second bit of code is that the second assumes $_GET['id'] exists. If it doesn't PHP will throw a warning.
savior14
Forum Newbie
Posts: 2
Joined: Thu Mar 04, 2010 12:46 am

Re: how does $_GET, $_POST, $_REQUEST works?

Post by savior14 »

thanks for the past reply =)
User avatar
garygay
Forum Newbie
Posts: 5
Joined: Thu Mar 04, 2010 4:03 am

Re: how does $_GET, $_POST, $_REQUEST works?

Post by garygay »

hi

Code: Select all

 
isset($_GET) ? $_GET : '';
 
:oops:
marty pain
Forum Contributor
Posts: 105
Joined: Thu Jun 11, 2009 5:32 am
Location: Essex

Re: how does $_GET, $_POST, $_REQUEST works?

Post by marty pain »

Both POST and GET are part of the HTTP protocol. This information is passed over to PHP by the web server when a page is requested.

Read up on HTTP if you are interested, but if not you can just assume that $_POST is always available (even though it may have no values set) and $_GET needs to be checked before you use it.
Post Reply