GET, POST and REQUEST Variables
Created by: Dr.Ferrous
The $_GET variable is a superglobal Array that contains data from a form sent with method="get" or from URL.
Information sent from a form with the GET method will be displayed in the browser's address bar (so, is visible to everyone) and has limits on the amount of data to send (about 2,048 characters).
After the user fills the form and clicks the "submit" (Send) button, the URL sent to the server could look something like this:
The "script.php" file can use the $_GET variable /array to collect form data (the names of the form fields are the keys in the $_GET array).
If you want to use in a PHP script data sent directly from a link, that data must be added in the URL address after the "?" character, in key=value pairs separated by "&" character.
This link example has an URL with two keys in the query string (after the "?" character), one called src and the other called id. In the "index.php" file you can manipulate these values. All you have to do is reference the key within the $_GET.
The $_POST variable is a superglobal Array that contains data from a form sent with method="post".
Information sent from a form with the POST method is invisible to the user and hasn't a specified limit on the amount of information to send. By default, PHP permits up to 8MB of POST data (can be changed from the post_max_size in the php.ini file).
When the user clicks the "submit" (Send) button, script.php is called, the URL will look like this:
The "script.php" file can use the $_POST variable /array to collect form data (the names of the form fields are the keys in the $_POST array).
The PHP $_REQUEST variable is a superglobal Array that contains the contents of both $_GET, $_POST, and $_COOKIE arrays. It can be used to collect data sent with both the GET and POST methods.
This code submits a form via the POST method, and when the form is posted, the code sends some values along the URL via the GET method ( "id=789", defined in the address from "action" attribute). The URL will look like this:
The sent data are loaded in the superglobal $_REQUEST variable /array, and can be used to collect both GET and POST data. For example:
If there are data received via GET and POST at the same time (through URL address and from a form), with the same "name" to both ($_GET['name'] and $_POST['name'), the $_REQUEST['name'] will contain the value of $_POST['name'].