note 32736 deleted from function.get-magic-quotes-gpc by aidan
| From: | aidan@php.net | Date: | Tue, 06 Jul 2004 06:20:30 +0000 |
| Subject: | note 32736 deleted from function.get-magic-quotes-gpc by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72698@lists.php.net to get a copy of this message | ||
Note Submitter: Captain America
----
IMHO gpc magic quotes are absolutely ill-featured, here is a way to fight them! :) Place it before
any other code that uses $_GET, $_POST or $_COOKIES. Works with multi-dimensional arrays!
WARNING: if you choose to stip the slashes, be sure to always add them manually if you insert GPC
vars in a SQL-query. addslashes() and mysql_escape_string() are your friends.
function & strip_slashes(&$str)
{
if(is_array($str))
{
while(list($key, $val) = each($str))
{
$str[$key] = strip_slashes($val);
}
}
else
{
$str = stripslashes($str);
}
return $str;
}
if(get_magic_quotes_gpc())
{
strip_slashes($_GET);
strip_slashes($_POST);
strip_slashes($_COOKIES);
}