note 36478 deleted from function.get-magic-quotes-gpc by aidan
| From: | aidan@php.net | Date: | Tue, 06 Jul 2004 06:19:54 +0000 |
| Subject: | note 36478 deleted from function.get-magic-quotes-gpc by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72693@lists.php.net to get a copy of this message | ||
Note Submitter: ryan@wonko.com
----
To make my scripts as slashproof as possible, I find it most convenient to disable
set_magic_quotes_runtime and, if get_magic_quotes_gpc returns 0, step through the $_GET, $_POST, and
$_COOKIE arrays and add slashes to everything.
This ensures that any database operations I perform using user-supplied data will be safe, and I
won't need to strip slashes from any data coming out of the database before displaying it. The
only thing I'll need to remember is to strip slashes from any data that I display straight from
the GET/POST/COOKIE arrays, but that's a minor inconvenience.
This code also elegantly handles nested arrays within GET/POST/COOKIE data.
<?
set_magic_quotes_runtime(0);
if (get_magic_quotes_gpc() == 0)
{
function magicSlashes($element)
{
if (is_array($element))
return array_map("magicSlashes", $element);
else
return addslashes($element);
}
// Add slashes to all incoming GET/POST/COOKIE data.
$_GET = array_map("magicSlashes", $_GET);
$_POST = array_map("magicSlashes", $_POST);
$_COOKIE = array_map("magicSlashes", $_COOKIE);
}
?>