note 17433 added to function.get-magic-quotes-gpc
| From: | ernst at baschny dot de | Date: | Sat, 08 Dec 2001 14:37:55 +0000 |
| Subject: | note 17433 added to function.get-magic-quotes-gpc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-22068@lists.php.net to get a copy of this message | ||
To disable magic_quotes_gpc in your script you can't just
ini_set-it, because at that time the variables are already written
by PHP. So you can only walk through all variables and stripslashes
them individually. To even walk into deeply nested arrays, you can
try this:
if (ini_get("magic_quotes_gpc") == 1) {
// Stripslashes recursively
function strip_rec($this) {
if (is_array($this)) {
while (list($key, $val) = each($this)) {
$this[$key] = strip_rec($val);
}
} else {
$this = stripslashes($this);
}
return $this;
}
$HTTP_POST_VARS = strip_rec($HTTP_POST_VARS);
$HTTP_GET_VARS = strip_rec($HTTP_GET_VARS);
$HTTP_COOKIE_VARS = strip_rec($HTTP_COOKIE_VARS);
// "Register globals?"
if (ini_get("register_globals")) {
if (is_array($HTTP_POST_VARS)) {
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $$key = $val; }
}
if (is_array($HTTP_GET_VARS)) {
while (list ($key, $val) = each ($HTTP_GET_VARS)) { $$key = $val; }
}
if (is_array($HTTP_COOKIE_VARS)) {
while (list ($key, $val) = each ($HTTP_COOKIE_VARS)) { $$key = $val; }
}
}
}
--
http://www.php.net/manual/en/function.get-magic-quotes-gpc.php
http://master.php.net/manage/user-notes.php?action=edit+17433
http://master.php.net/manage/user-notes.php?action=delete+17433
http://master.php.net/manage/user-notes.php?action=reject+17433