Skip to content

Instantly share code, notes, and snippets.

@triple-j
Created November 25, 2013 20:12
Show Gist options
  • Save triple-j/7648009 to your computer and use it in GitHub Desktop.
Save triple-j/7648009 to your computer and use it in GitHub Desktop.
counteract magic quotes if they are enabled (http://www.php.net/manual/en/security.magicquotes.disabling.php#71817)
<?php
// counteract magic quotes if they are enabled (http://www.php.net/manual/en/security.magicquotes.disabling.php#71817)
if (get_magic_quotes_gpc()) {
function undoMagicQuotes($array, $topLevel=true) {
$newArray = array();
foreach($array as $key => $value) {
if (!$topLevel) {
$key = stripslashes($key);
}
if (is_array($value)) {
$newArray[$key] = undoMagicQuotes($value, false);
} else {
$newArray[$key] = stripslashes($value);
}
}
return $newArray;
}
$_GET = undoMagicQuotes($_GET);
$_POST = undoMagicQuotes($_POST);
$_COOKIE = undoMagicQuotes($_COOKIE);
$_REQUEST = undoMagicQuotes($_REQUEST);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment