|
Here's the scenario - One day, out of the blue, your good old php driven website stops working correctly because all the variables you used to pass via URL now seem to disappear someplace between the browser address bar and your webpage. For example,
http://{ yourdomain }/index.php?key1=value1&key2=value2 <?php global $key1, $key2; ?>
The globals $key1 and $key2 are both empty because they are not passed from the URL.
Why? It's probably because your web host has disabled php's register_globals setting in php.ini for security purposes. Or another scenario is that you found a new host for your old php website, but the host has register_globals set to off and recoding your entire website is just not an option. If you don't know what your php settings are, you can easily find out by using php_info.php. You can download it HERE. Some situations allow you to decide if register_globals is on or off, but it is advised to leave it off due to security risks. In some cases, you can use your website's .htaccess file to set register_globals by adding the following line to the file - php_flag register_globals on or php_flag register_globals off Recent versions of php will probably return a 500 error with this method. In other cases, you can create your own php.ini file in your root folder and set register_globals to on or off. This depends on your host or hosting plan. Ask your host. If all you need to do is pass variables from the URL to a php script, the the fix may be as simple as one line of code in the script. parse_str($_SERVER['QUERY_STRING']); That will make all of the variables and their values from the URL available to the php script without the need for globals.
Please login or register to add comments |