Supporting legacy code, using global variables and register_globals with PHP 5.4.x

Recently we ran into some issues with some of our old sites that are relying on the register_globals  for variable access after upgrading to PHP 5.4 which wisely no longer supports this kind of setup.  Using globals in this fashion  is a horrible practice, but sometimes you gotta maintain some legacy code.

To use global variables you can add a line of code to htaccess that will run a “globalizer” file before loading the main page on every page load and extract the required variables.

globalizer.php file


htaccess update

# Relative path to the 'globalizer' file, in this example it's in webroot
php_value auto_prepend_file ./globalizer.php

Hope this helps.