note 48227 added to security.globals
| From: | alex at sourcelibre dot com | Date: | Wed, 15 Dec 2004 19:56:22 +0000 |
| Subject: | note 48227 added to security.globals | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81830@lists.php.net to get a copy of this message | ||
This is a simple function to make the register globals OFF and magic_quotes_gpc ON.
aalex
<?php
function safe_php() {
/**
* Lets verify the PHP configuration.
*/
$register_globals = ini_get('register_globals');
$magic_quotes_gpc = ini_get('magic_quotes_gpc');
/**
* Get super gloabals. We don't need $_SERVER, $_FILES and $_ENV.
*/
$superglobals = array('_GET', '_POST',
'_COOKIE','_REQUEST');
/**
* Now, let's clean it up !
*/
foreach ($superglobals as $superglobal) {
if (is_array($superglobal)) {
foreach ($$superglobal as $key => $val) {
/**
* Unset global variables GET, POST and COOKIE if register_globals is on.
*/
if ($register_globals) {
unset($GLOBALS[$key]);
}
/**
* Make sure magic_quote_gpc is on, or addslashes() yourself if not.
*/
if (!$magic_quotes_gpc) {
if (is_array($key)) {
foreach($key as $a_key => $a_value) {
$a_key =addslashes($a_value);
$$superglobal['$key']['a_key'] = $a_key;
}
} else {
$key =addslashes($value);
$$superglobal['$key'] = $key;
}
}
}
}
}
return TRUE;
}
?>
----
Manual Page -- http://www.php.net/manual/en/security.globals.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48227
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48227&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48227&report=yes
Search -- http://master.php.net/manage/user-notes.php