I would like to know how to emulate register globals = off in my php scripts. The server has it turned on and I can't change that so how do I work around it for my pages?

    If you can use a .htaccess, then it's very simple...

    php_flag register_globals off

    Otherwise, this code seems to do the job :

    <?php
     echo '<pre>';
     $arrKeep	= array('GLOBALS', '_GET', '_POST', '_FILES', '_COOKIE', 'arrKeep');
     $strDelete	= 'Delete me !';
     print_r($GLOBALS);
     foreach(array_keys($GLOBALS) as $strKey) {
    	if(!in_array($strKey, $arrKeep)) {
    		unset($GLOBALS[$strKey]);
    	}
     }
     unset($strKey);
     unset($arrKeep);
     print_r($GLOBALS);
    ?>

      Your best bet is to get them to turn it back off. You can't host a PHP web site when configuration changes are being made unilaterally and without consultation.

      Tell them that if they do any further configuration changes without your explicit permission, you will discontinue your contract.

      I use:

      if (ini_set('register_globals')) {
       throw new Exception("Register globals should always be off for this application to work");
      }
      

      Or similar.

      Mark

        Write a Reply...