What is a predefined superglobal? The short answer is that it is a variable that is defined by PHP that is available for you to use at any time on any page. Basically, PHP has already defined several helpful variables so that you don't have to do it yourself. They have also defined the scope of the variables as everywhere. There's nothing special you have to do to make PHP use these variables and they are very useful when you need to pass information from one page to another. While there are several more of these particular variables we will be discussing $_SERVER, $_GET,and $_POST specifically. You can check out Predefined Variables and Superglobals on the PHP website for more information on the others. These variables are associative arrays which means that they use strings as the indexes for the arrays.
$_SERVER is the first superglobal. It is an array that contains information from the web server such as headers, paths, and script locations. You have to be careful with $_SERVER because all servers are different and the information provided by one server won't always be provided by every server.
There are several ways to invoke $_SERVER. As you know it is an array with named indexes and can be invoked using the foreach method. This will provide you with the variables and the index names for all the information provided by the $_SERVER array. You can also access individual indexes, if you don't want to list everything, by using the standard array syntax.
Warning: highlight_file(server_example.php) [function.highlight-file]: failed to open stream: No such file or directory in /home/content/40/11808740/html/index.php on line 70
Warning: highlight_file() [function.highlight-file]: Failed opening 'server_example.php' for highlighting in /home/content/40/11808740/html/index.php on line 70
The following is typical output from the $_SERVER:
Fatal error: Call to undefined function printR() in /home/content/40/11808740/html/index.php on line 72