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?
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.
$_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 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']).
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With