I was having a hell of a time trying to get my site I built to work with both magic quotes on or off.. Someone gave me the following code.. Although i was very reluctant to use it, eventually I tried it worked flawlessly.. Put this at the top of each page..
Code:
if (get_magic_quotes_gpc())
{
if (!empty($_GET)) {
$_GET = strip_magic_quotes($_GET);
}
if (!empty($_POST)) {
$_POST = strip_magic_quotes($_POST);
}
if (!empty($_COOKIE)) {
$_COOKIE = strip_magic_quotes($_COOKIE);
}
}
add this function either in the same file or in a php include file if you already have one that contains functions for your site..
Code:
function strip_magic_quotes($arr)
{
foreach ($arr as $k => $v)
{
if (is_array($v))
{ $arr[$k] = strip_magic_quotes($v); }
else
{ $arr[$k] = stripslashes($v); }
}
return $arr;
}
then just code your entire site as though magic quotes are off.. Although this is a bit wasteful if magic quotes is off already(you could always just delete it if you know your host will not have magic quotes on.. however i was putting the site on a host who i was not sure if i could change the magic quotes setting for because he had a couple other sites he was hosting that used php). All it does is strip all magic quotes that have been added in.. Just make sure that you use mysql_real_escape_string before inserting any form data into your db..
Bookmarks