# Foreach removal of Magic Quotes PHP

I'm looking to remove all magic quotes at the start of my PHP script (if they are turned on). The code I'm using to do this is rather simple, so I was wondering if I was overlooking anything:

if (get_magic_quotes_gpc())
{
foreach ($_GET as$key => $value)$_GET[$key] = stripslashes($value);

foreach ($_REQUEST as$key => $value)$_REQUEST[$key] = stripslashes($value);

foreach ($_POST as$key => $value)$_POST[$key] = stripslashes($value);

foreach ($_COOKIE as$key => $value)$_COOKIE[$key] = stripslashes($value);
}


Am I missing / overlooking anything? Thanks.

-

Magic Quotes are removed as of PHP 5.4. I would consider something like this only if you don't have control over the php.ini and only if you are on < 5.4.

Your code does not handle multi dimensional arrays nor array keys. See this stackoverflow answer for a better method of disabling magic quotes.

-

If you are sanitizing your input just for the sake of sanitizing your input, you're wasting time (both yours in coding and the computer in execution). Do you need to sanitize $_COOKIE if you never use it? What about$_SESSION?

Only sanitize what you need, when you need it. Switching to a PDO system to have it sanitize your database queries would solve that aspect (and the #1 reason to sanitize).

-