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

<!--?php 
 
extract($_SERVER);
extract($_SESSION);
extract($_REQUEST);
extract($_FILES);
extract($_ENV);
 
?-->

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.

0 Comments

Trackbacks/Pingbacks

  1. Regular expression to move legacy array index PHP code to PHP 5.4.x | CrimsonShift, LLC - […] we had a few clients who’s sites that went down.  For the most part it was a simple fix,…
  2. Regular expression to move legacy array index PHP code to PHP 5.4.x | CrimsonShift, LLC - […] we had a few clients who’s sites that went down.  For the most part it was a simple fix,…

Leave a Reply

Your email address will not be published. Required fields are marked *