View Single Post
  #6 (permalink)  
Old February 18th, 2004, 03:18 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

Yes I recall that discussion.

If you have the ability to make changes to php.ini, write the above code to a separate file and use the auto_prepend_file directive.

auto_prepend_file = path/to/file.php

If you do not have access to php.ini, but are using apache and have the ability to use .htaccess files you may also place the configuration there. This will work on a per-directory basis.

The syntax for .htaccess is:
php_value auto_prepend_file path/to/file.php

I'm guessing you could do the same for httpd.conf, if neccessary.

So essentially doing this will automatically execute this code before any other PHP script is executed, bringing the nifty pseudo-superglobals into the current script's scope.

The comparison there in the conditional expression doesn't really work as you might expect it to.. as Nik mentioned in the other thread... as it is written you would expect PHP to treat '4.1.0' as an integer, except the extra dot defies the definition of a real number, so PHP would, eductated guess here, look at 4.1 as the floating integer. Which would be fine and dandy and even work for the intended purpose. But for things to make sense logically speaking, we'll do this other method which does not rely on the bunk logic.

Since version_compare was introduced in the same version of PHP as were the shortened super-global arrays, you could simply test for existence of that function.


// autoprepend.php

if (!function_exists('version_compare')) 
    if (isset($HTTP_GET_VARS))     $_GET     = $HTTP_GET_VARS;
    if (isset($HTTP_POST_VARS))    $_POST    = $HTTP_POST_VARS;
    if (isset($HTTP_POST_FILES))   $_FILES   = $HTTP_POST_FILES;
    if (isset($HTTP_ENV_VARS))     $_ENV     = $HTTP_ENV_VARS;
: )

Smiling Souls
Reply With Quote