g
Printer Friendly Version

editor   Theresa Ann Applegate
BellaOnline's PHP Editor
 

PHP Superglobal Variables and Register_Globals

PHP has a special kind of variable which is called a superglobal. The reason these variables are special is because they are automatically available to any PHP program without the programmer creating or defining them in his program. You can think of them as "built-in" variables.

The way you will access these variables differs depending on whether register_globals is turned on or off on your server. Before PHP version 4.2, register_globals was turned on by default. However do to security reasons; this setting is now turned off by default (version 4.2+). Of course it is up to the people who run your server to decide whether to override the default setting and turn register_globals on. The easiest way to test your own server is to use the phpinfo(). You will probably have a link to this webpage in the administrative area of your website. On this webpage you will find the Configuration PHP Core section that has this information.

As mentioned above you will access the superglobals differently depending on the setting of your server. For the new server setup the superglobals were given new names. If your server still has the old setting, it would be better to start using the new names anyway. If you use these new names you can be sure that your programs will work under both server configurations. However, this is not the case for the old names. They will only work for the old server configuration. The chart below shows the old and new names and a description of the superglobals. Notice that the names of these superglobals are in all capital letters.

NewOldDescription
$_GET $HTTP_GET_VARS This superglobal contains the variables sent to the program by the get method such as a guery string.
$_POST $HTTP_POST_VARS This superglobal contains the variables sent to the program by the post method.
$_COOKIE $HTTP_COOKIE_VARS This superglobal contains the variables available to the program from a cookie.
$_SESSION $HTTP_SESSION_VARS This superglobal contains the variables registered by the program via a session.
$_FILES $HTTP_POST_FILES This superglobal contains the variables available from a file upload.
$_ENV $_HTTP_ENV_VARS This superglobal contains the variables available from the server environment.
$_REQUEST -- This superglobal contains the variables sent to a program by any type of user input. This is the most general or universal type of superglobal.
$_SERVER -- This superglobal contains information about the server such as file paths.




PHP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2009 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Theresa Ann Applegate for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2009 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor