PHP: how to (correctly) remove escaped quotes in arrays when Magic Quotes is enabled

As you know, when Magic Quotes is turned on, single quotes are escaped in values ​​as well as in keys. Most runtime magic quotes removal solutions have only unescape values, not keys. I am looking for a solution that will override keys and values ​​...

I recognized this code snippet on PHP.net:

$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); 

But I don't like "&" links and arrays as I had errors like this in the past ...

Is there a better way to unescape Magic Quotes (keys and values) at run time than the previous one?

+7
php magic-quotes
source share
2 answers

I think this is a little cleaner and avoids the links:

 function unMagicQuotify($ar) { $fixed = array(); foreach ($ar as $key=>$val) { if (is_array($val)) { $fixed[stripslashes($key)] = unMagicQuotify($val); } else { $fixed[stripslashes($key)] = stripslashes($val); } } return $fixed; } $process = array($_GET,$_POST,$_COOKIE,$_REQUEST); $fixed = array(); foreach ($process as $index=>$glob) { $fixed[$index] = unMagicQuotify($glob); } list($_GET,$_POST,$_COOKIE,$_REQUEST) = $fixed; 
+7
source share
 array_walk_recursive($_POST, 'stripslashes'); 

Do the same for GET and COOKIE.

-one
source share

All Articles