note 53961 added to faq.misc
| From: | markus at osu1 dot php dot net | Date: | Sat, 18 Jun 2005 22:34:33 +0000 |
| Subject: | note 53961 added to faq.misc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90634@lists.php.net to get a copy of this message | ||
Considering the comment below. I think there's a way to avoid that "problem":
<?php
//
// $starttime is an example of a variable that we might need to define,
// even before, running the "register_globals OFF" emulator below.
//
list($msec, $sec) = explode(' ', microtime());
$starttime = ((float)$msec + (float)$sec);
//
// If register_globals is ON, ensure no unexpected globals are defined.
// ie. We'll try to emulate a register_globals OFF environment.
//
if( (bool)@ini_get('register_globals') )
{
$superglobals = array($_ENV, $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
if( isset($_SESSION) )
{
array_unshift($superglobals, $_SESSION);
}
$knownglobals = array(
//
// Known PHP Reserved globals and superglobals:
//
'_ENV', 'HTTP_ENV_VARS',
'_GET', 'HTTP_GET_VARS',
'_POST', 'HTTP_POST_VARS',
'_COOKIE', 'HTTP_COOKIE_VARS',
'_FILES', 'HTTP_FILES_VARS',
'_SERVER', 'HTTP_SERVER_VARS',
'_SESSION', 'HTTP_SESSION_VARS',
'_REQUEST',
//
// Global variables used by this code snippet:
//
'superglobals',
'knownglobals',
'superglobal',
'global',
'void',
//
// Known global variables defined before this code snippet is reached.
//
'starttime',
);
foreach( $superglobals as $superglobal )
{
foreach( $superglobal as $global => $void )
{
if( !in_array($global, $knownglobals) )
{
unset($GLOBALS[$global]);
}
}
}
}
?>
Note the stuff related to the $_SESSION array depends on whether the PHP session has been started or
not. You might want to call session_start() before this point (or set session.auto_start ON).
HTH+ :)
----
Manual Page -- http://www.php.net/manual/en/faq.misc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53961
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53961&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53961&report=yes
Search -- http://master.php.net/manage/user-notes.php