Super Globals

Scope is valid anywhere

 

$GLOBALS

Associative array containing all global variables currently available within the global scope of the script, including ALL other super globals.

 

The Super Global variables are recognisable by their $_ prefix followed by the rest of their name in UPPERCASE

 

$_SERVER

Associative array containing all variables set by the web server, or other sources that directly related to the execution of the script.

 

 

$_GET

Contains all variables sent by HTTP GET request to the script via URL query string

 

IMPORTANT: Data sent with the GET method is limited and visible to everyone (i.e. displayed in the browser's address bar)

The top half of the above code asks the user to enter their name

Upon submit, the data is sent using the GET method to the file specified in the form action: "get.php"

The lower half of the above code (get.php) displays the data sent, which can be seen in it's URL

e.g. https://php.tech-academy.co.uk/get.php?yourName=DerrickĀ *(unsafe for sensitive data!)

The names of the form fields are used as the keys in the $_GET array

 

 

$_POST

Contains all variables sent via a HTTP POST request.

 

IMPORTANT: Data sent with the POST method is invisible and has no limits on the amount of data to send (default is 8MB, can be changed by post_max_size in php.ini)

The top half of the above code asks the user to enter their name

Upon submit, the data is sent using the POST method to the file specified in the form action: "post.php"

The lower half of the above code (post.php) displays the data sent, but cannot be seen in it's URL

e.g. https://php.tech-academy.co.uk/post.php

The names of the form fields are used as the keys in the $_POST array

 

 

$_COOKIE

Associative array containing all variables sent via HTTP cookies

 

 

$_FILES

Associative array containing all variables sent via HTTP POST file upload

The top half of the above code provides user with choose file form, followed by Submit button

Upon submit, the data is sent using the POST method to the file specified in the form action: "post.php"

The lower half of the above code (fileUpload.php) displays the contents of the $_FILES array

Just for completeness, the last two lines copy the file from its temp location for permanent storage

 

 

$_ENV

Associative array containingĀ all environment variables set by your system or shell for the script

*Probably quite dangerous to have this as a live script, since it shows a little too much information!

 

 

$_REQUEST

Associative array containing the contents of $_GET, $_POST and $_COOKIE

Beware: contains all variables from untrusted sources (e.g., site visitors), best to avoid unless really necessary

The top half of the above code asks the user to enter their name

Upon submit, the data is sent using the POST method (GET could alternatively have been used) to the file specified in the form action: "request.php"

The lower half of the above code (request.php) displays the data sent

The names of the form fields are used as the keys in the $_REQUEST array

 

 

$_SESSION

Contains all variables stored in a user's session

Leave a Reply