note 97783 added to function.get-magic-quotes-gpc
| From: | hetored at gmail dot com | Date: | Fri, 07 May 2010 21:17:11 +0000 |
| Subject: | note 97783 added to function.get-magic-quotes-gpc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169064@lists.php.net to get a copy of this message | ||
Here's what I came up with to remove magic quotes from request data.
Replaces two single-quotes with one if magic_quotes_sybase are on, otherwise it just strips slashes.
Note that the
foreach style makes this work only with PHP 5 and above.
<?php
// Strip magic quotes from request data.
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
// Create lamba style unescaping function (for portability)
$quotes_sybase = strtolower(ini_get('magic_quotes_sybase'));
$unescape_function = (empty($quotes_sybase) || $quotes_sybase === 'off') ?
'stripslashes($value)' :
'str_replace("\'\'","\'",$value)';
$stripslashes_deep = create_function('&$value, $fn', '
if (is_string($value)) {
$value = ' . $unescape_function . ';
} else if (is_array($value)) {
foreach ($value as &$v) $fn($v, $fn);
}
');
// Unescape data
$stripslashes_deep($_POST, $stripslashes_deep);
$stripslashes_deep($_GET, $stripslashes_deep);
$stripslashes_deep($_COOKIE, $stripslashes_deep);
$stripslashes_deep($_REQUEST, $stripslashes_deep);
}
?>
----
Server IP: 80.67.10.226
Probable Submitter: 82.182.121.197
----
Manual Page -- http://www.php.net/manual/en/function.get-magic-quotes-gpc.php
Edit -- https://master.php.net/note/edit/97783
Del: integrated -- https://master.php.net/note/delete/97783/integrated
Del: useless -- https://master.php.net/note/delete/97783/useless
Del: bad code -- https://master.php.net/note/delete/97783/bad+code
Del: spam -- https://master.php.net/note/delete/97783/spam
Del: non-english -- https://master.php.net/note/delete/97783/non-english
Del: in docs -- https://master.php.net/note/delete/97783/in+docs
Del: other reasons-- https://master.php.net/note/delete/97783
Reject -- https://master.php.net/note/reject/97783
Search -- https://master.php.net/manage/user-notes.php