Some Variables are Special.
Some variables have a special purpose in PHP, that is they are reserved to hold specific values and are created by PHP itself, also built in function names cannot be used as variable names.
The PHP manual has a full list of these variables, but some of the more important ones are the array collections $_POST , $_GET , $_REQUEST, $_SERVER and $_ENV, We’ll cover arrays in more detail at a later date, but for now if you look at the phpinfo script that we created in the second article in the series, you’ll see near the bottom that there is a list of the elements in the $_SERVER and $_ENV variables.
To get the value of these variables simply use the variable name followed by the item name quoted in square brackets, eg:
print $_SERVER["SERVER_ADDR"];
The $_POST, $_GET and $_REQUEST variables are populated by values passed to your script. We’ll look at $_POST in the article on arrays, but for now if you try running your script usinghttp://localhost/myscript.php?myvar=hello&age=21, you’ll find that the variables$_GET["myvar"] and $_GET["age"] will hold the values “hello” and 21 respectively.
Advertisements