Page 1 of 1

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

Posted: Thu Mar 04, 2010 12:57 am
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')
{
}
}

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

Posted: Thu Mar 04, 2010 1:14 am
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.

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

Posted: Thu Mar 04, 2010 1:30 am
by savior14
thanks for the past reply =)

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

Posted: Thu Mar 04, 2010 4:43 am
by garygay
hi

Code: Select all

 
isset($_GET) ? $_GET : '';
 
:oops:

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

Posted: Thu Mar 04, 2010 5:01 am
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.