PHP GET and POST

In this chapter you will learn:

  1. GET POST Superglobal Array
  2. Example - Accept value from $_GET and $_REQUEST
  3. Different between 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.

Next chapter...

What you will learn in the next chapter:

  1. Form Element List
  2. Example - Form Element
Home » PHP Tutorial » PHP Form
PHP HTML Forms
PHP GET and POST
PHP Form Elements
PHP Form TextField
PHP Form Password Field
PHP Form Textarea
PHP Form CheckBox
PHP Form Select
PHP Form RadioButton
PHP Form Submit
PHP Form Reset
PHP Form Push Button
PHP Form Image
PHP Form Hidden Field
PHP Split Form Across Pages
PHP Form Validation
PHP Form File Upload
PHP Form Demo
PHP Form Empty Fields
PHP Form Multi-Value Fields
PHP Redirect after a Form Submission