What's difference between $_REQUEST and $_POST ?

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
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

What's difference between $_REQUEST and $_POST ?

Post by Mds »

Hi there.
What's difference between $_REQUEST and $_POST ?
And which of them is better to using ?

Thank you.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: What's difference between $_REQUEST and $_POST ?

Post by Dynamis »

Mds wrote: What's difference between $_REQUEST and $_POST ?
"The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.

The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods."

W3Schools
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

Re: What's difference between $_REQUEST and $_POST ?

Post by Mds »

Thank you.
I want to get POST data by my PHP's page.
Is it better to use $_REQUEST or $_POST ? :?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: What's difference between $_REQUEST and $_POST ?

Post by shiznatix »

it is much better practice to use the specific superglobal instead of $_REQUEST. This way you know for sure were your variables are coming from and you won't have any collisions. Plus it makes it clearer when looking back at old code where you are getting your variables. So, in your case, use $_POST.
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: What's difference between $_REQUEST and $_POST ?

Post by Dynamis »

shiznatix wrote:it is much better practice to use the specific superglobal instead of $_REQUEST. This way you know for sure were your variables are coming from and you won't have any collisions. Plus it makes it clearer when looking back at old code where you are getting your variables. So, in your case, use $_POST.
I agree.
User avatar
Mds
Forum Contributor
Posts: 110
Joined: Tue Apr 22, 2008 8:56 pm
Contact:

Re: What's difference between $_REQUEST and $_POST ?

Post by Mds »

OK, I got it :wink:
Thanks guys.
Post Reply