PHP GET and POST

Superglobal Array

To read the data from a form, we can use the following three superglobal variables.

Superglobal ArrayDescription
$_GETContains all the field names and values sent by a form using the get method
$_POSTContains all the field names and values sent by a form using the post method
$_REQUESTContains the values of both the $_GET and $_POST arrays combined, along with the values of the $_COOKIE superglobal array

Example

Each of these three superglobal arrays contains the field names from the sent form as array keys, with the field values themselves as array values.


<input type="text "  name="emailAddress" value="" />  

You could then access the value that the user entered into that form field using either the $_GET or the $_REQUEST superglobal:


$email = $_GET["emailAddress"]; 
$email = $_REQUEST["emailAddress"];     

Different between GET and POST

GET sends its variables in the URL. It easy to see what was sent with GET. And user can change what was sent There is usually a low limit on the number of characters that can be sent in a URL. If we try to send long variables using GET, we may lose some of them.

POST sends its variables behind the scenes and has a much higher limit. It limit is usually several megabytes.

Browsers will not automatically resend post data if your user clicks the Back button, you may get a message like "The data on this page needs to be resent". This does not happen with GET, browsers will just resend data as needed through URL.

PHP has post_max_size entry in php.ini. It is usually set to 8M by default, which is 8 megabytes.





















Home »
  PHP Tutorial »
    Form »




PHP Form
Form Demo