Log in

View Full Version : Resolved page specific php.ini



james438
05-03-2011, 11:08 PM
Hi,

Is there a way to use php to turn off magic quotes for a particular file if it is on without editing the php.ini file or .htaccess?

james438
05-03-2011, 11:20 PM
Silly me. The answer is right on the php.net site here (http://www.php.net/manual/en/security.magicquotes.disabling.php).

Just insert the following near or at the top of your php script.

<?php
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);
}
?>

It is not as efficient as changing the php.ini file, but it can make your scripts more portable.