note 50730 added to security.magicquotes
| From: | luciano at vittoretti dot com dot br | Date: | Tue, 08 Mar 2005 13:08:45 +0000 |
| Subject: | note 50730 added to security.magicquotes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86101@lists.php.net to get a copy of this message | ||
If you dont want to use magic quotes, and have no permissions to disable that feature, use this
function:
<?
function table_manager_no_magic_quotes() {
if (!function_exists("table_manager_no_magic_quotes_aux")) {
function table_manager_no_magic_quotes_aux() {
if (ini_get("magic_quotes_gpc")) {
$trocar = Array();
if (ini_get("magic_quotes_sybase")) {
$trocar[] = Array("'", "''");
} else {
$trocar[] = Array("'", "\'");
$trocar[] = Array("\"", "\\\"");
$trocar[] = Array("\\", "\\\\");
}
foreach($trocar AS $troca) {
foreach($GLOBALS["HTTP_GET_VARS"] As $name => $var) {
$GLOBALS["HTTP_GET_VARS"][$name] = str_replace($troca[1], $troca[0], $var);
$GLOBALS["_GET"][$name] = str_replace($troca[1], $troca[0], $var);
}
foreach($GLOBALS["HTTP_COOKIE_VARS"] As $name => $var) {
$GLOBALS["HTTP_COOKIE_VARS"][$name] = str_replace($troca[1], $troca[0], $var);
$GLOBALS["_COOKIE"][$name] = str_replace($troca[1], $troca[0], $var);
}
foreach($GLOBALS["HTTP_POST_VARS"] As $name => $var) {
$GLOBALS["HTTP_POST_VARS"][$name] = str_replace($troca[1], $troca[0], $var);
$GLOBALS["_POST"][$name] = str_replace($troca[1], $troca[0], $var);
}
}
if (ini_get("register_globals")) {
$order = ini_get("variables_order");
for($i = 0;$i < strlen($order);$i++) {
$kind_array = null;
switch ($order[$i]) {
case "E":
if (isset($GLOBALS["HTTP_ENV_VARS"])) {
$kind_array = $GLOBALS["HTTP_ENV_VARS"];
}
break;
case "G":
if (isset($GLOBALS["HTTP_ENV_VARS"])) {
$kind_array = $GLOBALS["HTTP_ENV_VARS"];
}
break;
case "P":
if (isset($GLOBALS["HTTP_POST_VARS"])) {
$kind_array = $GLOBALS["HTTP_POST_VARS"];
}
break;
case "C":
if (isset($GLOBALS["HTTP_COOKIER_VARS"])) {
$kind_array = $GLOBALS["HTTP_COOKIE_VARS"];
}
break;
case "S":
if (isset($GLOBALS["HTTP_SESSION_VARS"])) {
$kind_array = $GLOBALS["HTTP_SESSION_VARS"];
}
break;
}
if (is_array($kind_array)) {
foreach($kind_array AS $var => $value) {
$GLOBALS[$var] = $value;
}
}
}
}
}
}
table_manager_no_magic_quotes_aux();
}
}
?>
If magic quotes isnt active this function wont do anything.
And if this function is already executed it wont execute again.
----
Manual Page -- http://www.php.net/manual/en/security.magicquotes.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50730
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50730&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50730&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50730&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50730&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50730&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50730&report=yes
Search -- http://master.php.net/manage/user-notes.php