133Chapter 7Passing Information between Pages?>
All GET, POST, COOKIE, ENVIRONMENT, and SERVERvariables were made global by the register_globalsdirective in php.iniand were directly accessible by their names bydefault. This was bad for several reasons. For one thing, every so often a COOKIEvariable would acci- dentally overwrite a POSTvariable of the same name although the developer didn t want thatto happen. For another thing, it led to big, messy, undifferentiated global namespaces. Mostimportant, allowing variables to be set by user input is very insecure. The PHP world had fartoo many inexperienced coders writing things like: without giving too much thought to the idea that a cracker could easily just call this page with aGETvariable named allaccesspassset to 1 and negate the advantages of any password check. The PHP team, in its infinite wisdom, decided to phase out the practice of registering globals, forcing everyone to call his variables as indices in an array (for example, $_POST[ secretpassword ]). This had already been possible in PHP4, via arrays named $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_POST_VARS, and so on, but few developers had used this syntax; frankly, it was a lot of extra keystrokes for a small increase in security. So the PHP team alsotook this opportunity to rename these arrays with shorter names: $_GET, $_POST, $_COOKIE, $_ENV, and $_SERVER. These superglobal arrays also have one cool feature that may ameliorate some pain: They areautomatically global everywhere. This means, for instance, that you no longer have to passcookie values into a function or declare the $HTTP_COOKIE_VARSarray global before you canaccess those values in a function. This will help those who functionalize to the max and willbe a small amelioration for everyone else. As of PHP4.2, register_globalsis officially turned off by default, and the old-style variablearray names are deprecated. Sooner or later, the PHP team will make register_globalsnotwork any more. It will take quite a while to move the entire PHP community over to the newsuperglobal arrays, but we feel obligated to try to use them as much as possible in this bookto set a good example. Save yourself a lot of trouble in the future and start using superglobalarrays. Although register_globalsis still an available option in PHP5 s php.inifile, setting it toondoes not, as of this writing, provide access to variables outside of the superglobal arrays. Caution09
Please visit our
professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.