PHP Register Long Arrays HTTP_POST_VARS

Posted in PHP -

I have been in the process of moving my websites from a dedicated machine running Gentoo Linux to a VPS (Virtual Private Server) running CentOS 5. One of the ecommerce websites uses an old install of osCommerce which expects register globals and register_long_arrays on, otherwise things won't work very well.

While testing the site out on the new server, I couldn't work out why some of the form posts were working and some weren't. For example, on some pages I could add items to the shopping cart but on others I couldn't. I also couldn't click the form button to proceed to th checkout or update my basket: whenever I tried it kept showing me the same basket page again.

After checking the obvious and making sure register_globals was enabled for this virtualhost like so:

<virtualhost 10.1.1.1:80>

    ServerName www.example.com
    DocumentRoot /var/www/example.com
    php_value register_globals 1

</virtualhost>

things still weren't working, so I had to dive into the code that runs some of these pages. The first thing I noticed was the use of $HTTP_POST_VARS. I had assumed that this particular super global would have been enabled with the use of register_globals but it wasn't.

After a quick look at the PHP manual, I managed to work out that these particular old style superglobal arrays have their own special flag for enabling them, known as "register_long_arrays". It is then possible to enable them in a virtualhost by virtualhost basis as in the following example, modified from the above and with the new entry in bold:

<virtualhost 10.1.1.1:80>

    ServerName www.example.com
    DocumentRoot /var/www/example.com
    php_value register_globals 1
    php_value register_long_arrays 1

</virtualhost>

Having done this, the problem went away and the nasty osCommerce system worked again. I then checked the php.ini files of the old server and the new VPS server, and saw that this particular variable had been set on in the old server and obviously not in the new one, as this is a deprecated variable.

So it would be possible to add this to the php.ini file like so:

php_value register_long_arrays 1

but it's really not recommended because 1) you shouldn't be using these long arrays any more, and 2) there's an additional performance hit when it is enabled. Once we get to PHP 6 it won't even be an option any more.



Related posts:


Comments