GET/POST variables

GET and POST are two methods used to request data as part of the HTTP protocol.

GET variables

GET variables are sent using the query string of a URL, for example These values can be specified when calling a PHP script as with everything else.

POST variables

POST variables are not passed through the query string, instead requesting that a web server accepts the data enclosed in the body of the request message and uses that. They are accessed in a very similar way to GET variables.

Checking if a GET/POST variable has been specified

If a GET/POST variable is not specified in the request, and is referenced by the program, an error will be thrown. To combat this we can use the below code.

if (!array_key_exists("item", $_GET) || $_GET["item"] == "") { 
	// either the item was not specified or was empty
	echo "item not specified";
} else {
	// the item was present and correct
	$thingy = $_GET["item"];