Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and why should $_REQUEST be used instead of $_GET / $_POST / $_COOKIE?

Tags:

Question in the title.

And what happens when all 3 of $_GET[foo], $_POST[foo] and $_COOKIE[foo] exist? Which one of them gets included to $_REQUEST?

like image 713
Imran Avatar asked Sep 20 '08 09:09

Imran


People also ask

What's the difference between $_ POST $_ GET and $_ request?

Now, There are total three super global variables to catch this data in PHP. $_POST : It can catch the data which is sent using POST method. $_GET : It can catch the data which is sent using GET method. $_REQUEST : It can catch the data which is sent using both POST & GET methods.

What is the purpose $_ GET and $_ POST variable?

$_GET, and $_POST are array variables of PHP which are used to read submitted data by HTML form using the get and post method accordingly.

How can we use $_ GET $_ POST $_ request variable in PHP?

How to use it? Before you can use the the $_POST variable you have to have a form in html that has the method equal to POST. Then in the php, you can use the $_POST variable to get the data that you wanted. The $_POST syntax is ($_POST['name of the form field goes here']).

What is use of $_ request in PHP?

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.


1 Answers

I'd say never.

If I wanted something to be set via the various methods, I'd code for each of them to remind myself that I'd done it that way - otherwise you might end up with things being overwritten without realising.

Shouldn't it work like this:

$_GET = non destructive actions (sorting, recording actions, queries)

$_POST = destructive actions (deleting, updating)

$_COOKIE = trivial settings (stylesheet preferences etc)

$_SESSION = non trivial settings (username, logged in?, access levels)

like image 185
Rich Bradshaw Avatar answered Oct 13 '22 23:10

Rich Bradshaw