For some reason, all my quotes are being escaped and displayed as \". Previously, it was okay. Then I looked at phpinfo() and saw that my magic_quotes_gpc is turned on. However, I cannot find the directory /usr/local/lib/ where php.ini file is and I cannot edit my .htaccess file (gets 500 Internal Server Error).
I tried putting this instead on top of my scripts file (which is included in all pages):
if (get_magic_quotes_gpc()) {
$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 still, the " and ' on my pages still have the backslashes in them.
What am I doing wrong?
Which PHP-version do you use?
If you use a version larger than
5.2
, than you can usefilter_input()
orfilter_input_array()
. It seems that it ignores the setting of themagic_quotes_gpc
-directive and uses the raw data (the default filter isFILTER_UNSAFE_RAW
)Give this code a try, it's worked for me in the past.