PHP Register Globals

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

I have a version of OSCommerce on a website, and the host has register_globals turned off. For whatever reason, OSC requires register_globals to be turned on. If there a script that will replicate register_globals being turned on for this one script? Thanks.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

I think it was in the joomla documentationt hat I saw something about how they have something to emulate Registered Globals for backwards compatability as they recommend that you have PHP's register_globals shut off.

My server has them turned on my default, and per Joomla's documentation to turn them off for my site I entered the following lines into the .htaccess file for where I have joomla installed. (Only the first one is for register globals)

[="Courier New"]php_flag register_globals off
php_flag magic_quotes_gpc on[/]

So maybe you can turn them on the same way, but for security, maybe want to look into emulation instead.

-Greg

PS. Ok, this has me wondering how they do the emulation, so I searched, and it looks like it is the registerGlobals function in the globals.php file that handles this if you turn the emulation on. May want to check into how they do it and see if you can figure a workaround.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Thanks so much for that info. I looked up Joomla's documentation, and sure enough, it's there. I've tried forcing register_globals with .htaccess file with no luck. I think I will just have to modify OSC with the emulation. IMHO, it was not smart of the OSC team to require register globals because of it's lack of security. Plus, I heard that it won't be an option in php 6.

Thanks again!

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I had a similar situation some years ago, found a script on php.net and modified it. Try the following script and see if it helps:

<?php
$global_vars_array
= array(\"_GET\", \"_POST\");
foreach(
$global_vars_array as $global_var)
  {
   
$keys = array_keys($$global_var);
    foreach(
$keys as $key)
      {
        $
$key = trim(${$global_var}[$key]);
      }
  }
?>

Edit, btw, you'll need to add that into every .php page which uses the global variables.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.