DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Strip Slashes From User Input (if Applicable)
This code checks if magic quotes are enabled, and if so, strips slashes from GET, POST and COOKIE arrays. It's fully recursive, and thus supports POST arrays.
<?php
// If magic quotes are enabled, strip slashes from all user data
function stripslashes_recursive($var) {
return (is_array($var) ? array_map('stripslashes_recursive', $var) : stripslashes($var));
}
if (get_magic_quotes_gpc()) {
$_GET = stripslashes_recursive($_GET);
$_POST = stripslashes_recursive($_POST);
$_COOKIE = stripslashes_recursive($_COOKIE);
}
?>





Comments
Ahsan Gill replied on Fri, 2013/05/10 - 6:45am
event security newry event security lisburn event security londonderry event security belfast event security armagh event security county-armagh event security swansea event security st asaph event security newport event security cardiff event security bangor event security stirling event security perth event security inverness event security glasgow event security edinburgh
Snippets Manager replied on Wed, 2008/08/20 - 6:32pm
<?php if (get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE); while (list($k,$v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } ?>Snippets Manager replied on Mon, 2012/05/07 - 2:12pm
Snippets Manager replied on Mon, 2012/05/07 - 2:12pm
if (get_magic_quotes_gpc()) { $_GET = stripslashes_recursive($_GET); $_POST = stripslashes_recursive($_POST); $_COOKIE = stripslashes_recursive($_COOKIE); }