Current course:

PHP "GET" variables

A "get" variable is a variable retrieved from the URL.
Example URL: http://digitalarts.bgsu.edu/interactive/code.php?c=php_get

The Code:

$code = $_GET['c'];
echo "code"; //echos "php_get"

The Explanation:

After the filename in the URL, there is a questionmark. This lets us know that the item after it is the name of a GET variable. It's followed by an equals sign, then the value of the variable.

So in the example above, "c" is the variable, and "php_get" is the variables value.

To retrieve the value, use $_GET['c'] - where "c" is the name of the variable you'd like to retrieve.

In the code above, we retrieve the variable from the URL and assign it to another variable we create named $code.

GET variables can be passed from HTML forms by using the "method" attribute and assigning it the value of "GET".

COMMON USE: A common use of GET variables is to use the same php page, but change it's contents based on the GET variable. For example, this page will display different classes depending on what the GET variable "class" is set to.

OTHER ITEMS POST variables (the other option) are essentially the same as GET variables, but require the information to be passed from an HTML form by giving the form a method attribute with value of "POST".