Difference between $_GET, $_POST and $_REQUEST

Written By Naveen on Tuesday, November 29, 2011 | 3:02 AM

$_GET, $_POST and $_REQUEST  all these variables are predefined variables in php. Normally we have 2 methods to send the data to one page to another page. Those methods are nothing but GET and POST methods. Using this variable we can get the data by specifying the variable name for example, $_GET['name'], $_POST['email'] and $_REQUEST['phone'].

Using GET method:
we can get the data from URL
Example: www.example.com/index.php?name=phptag
Now from the above URL if you want to get the phptag value see the code below

<?php

$name = $_GET['name'];
//or
$name = $_REQUEST['name'];

?>

Using POST method:
we can get the in hidden mode, that means we cannot see the data in URL it will carry through the headers.
Normally we can use the post method by implementing the html form's see the code below

<form name='phptag' method='post'>
     <input type='text' name='name' value='phptag'>
     <input type='submit' name='demo' value='Click' >
</form>
<?php

$name = $_POST['name'];
//or
$name = $_REQUEST['name'];

?>

In the above examples the common thing that we have used is $_REQUEST which means it can be used for both GET and POST methods to get the data.

15 comments:

ajey said...

It is Clear Difference.
Thanks

Vivek said...
This comment has been removed by the author.
Naveen said...

Thank you very much. If you have any queries please comment it here so that I can describe it in a new post.

Anonymous said...

Very clear explanation.. thnx :)
http://tg1927.blogspot.in/

Anonymous said...

what is diff b/w $post and $request

Anonymous said...

Nice example it helped me,Thanks

Anonymous said...

Nice example, But still one confusion is there, PHP have both type of global variable available that is $_POST and $_GET which can manage both kind of data whether it is get or post then why specially design $_REQUEST. is there any unique thing apart from these both?

naveen said...

we might need to use $_REQUEST in case if $_GET and $_POST are modified dynamically.
Please read through this link for better understanding: http://php.net/manual/en/reserved.variables.request.php

Unknown said...

Nice Example.................

Rahul said...

thank you it is very simple to undrstand

Rahul said...
This comment has been removed by the author.
Anonymous said...

thank you it is very simple to undrstand

yaklibber924 said...

I’m impressed, I need to say. Actually hardly ever do I encounter a weblog that’s both educative and entertaining, and let me inform you, you might have hit the nail on the head. Your thought is outstanding; the issue is something that not enough persons are speaking intelligently about. I'm very comfortable that I stumbled throughout this in my search for one thing referring to this. gsn casino games

Unknown said...

Nyc Example..................

Anonymous said...

casino with the slot machine - DRMCD
Slots.lv - Real 서울특별 출장샵 Time Gaming (RTG) Casino Online and offline 파주 출장샵 gambling site. You can play this casino online without any 용인 출장안마 registration or 광양 출장안마 registration. 군산 출장마사지

Post a Comment