PDA

View Full Version : Magic quotes in PHP


xariton
06-23-2005, 07:37 AM
Useful code to make magic_quotes=on and global=on when in php.ini magic_quotes=off and global=off
function stripslashes_deep($value)
{
return (is_array($value) ? array_map('stripslashes_deep', $value) : addslashes($value));
}

if (!get_magic_quotes_gpc())
{
$_GET = array_map('stripslashes_deep', $_GET);
$_POST = array_map('stripslashes_deep', $_POST);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

@import_request_variables("GPC");
extract($_SERVER);
extract($_POST);
extract($_COOKIE);
extract($_GET);

Just post it the beginning of your script

Yahook
06-23-2005, 10:02 AM
Thanks Xariton, very usefull script. But as for me I think that magic_quotes=off and global=off is very good for security.

xariton
06-23-2005, 12:02 PM
You are right :)
It can be useful when you don’t need security and you don’t want to add addslashes before each mysql query for example