With the addslashes attacks around, I really don't see the advantage to set up magic_quotes_on, sad enough, the new version php.ini default set it as on, so some servers may follow that set up too.
And people are taking about how to turn it off if the server set up is on.
PHP manual said let .htaccess not run time php codes do the work to change the magic_quotes_gpc set up to reduce the strain of the site.
But Apache said, to allow .htaccess it will increase the strain of the server, so let the run time php codes to be the solution.
Well, Apache will win because server administrator will speak for apache.
Here is the codes I get from the php manual
http://se2.php.net/magic_quotes/
Is this the best/comprehensive codes?
Imagine we have to add it to many pages of the php web site, just to do the damage control of the magic_quotes_gpc. Except the performance issues, is this code covering all the problems? Any missings here?
<?php
//Prevent Magic Quotes from affecting scripts, regardless of server settings
//Make sure when reading file data,
//PHP doesn't "magically" mangle backslashes!
set_magic_quotes_runtime(FALSE);
if (get_magic_quotes_gpc()) {
/
All these global variables are slash-encoded by default,
because magic_quotes_gpc is set by default!
(And magic_quotes_gpc affects more than just $GET, $POST, and $COOKIE)
/
$SERVER = stripslashes_array($SERVER);
$GET = stripslashes_array($GET);
$POST = stripslashes_array($POST);
$COOKIE = stripslashes_array($COOKIE);
$FILES = stripslashes_array($FILES);
$ENV = stripslashes_array($ENV);
$REQUEST = stripslashes_array($REQUEST);
$HTTP_SERVER_VARS = stripslashes_array($HTTP_SERVER_VARS);
$HTTP_GET_VARS = stripslashes_array($HTTP_GET_VARS);
$HTTP_POST_VARS = stripslashes_array($HTTP_POST_VARS);
$HTTP_COOKIE_VARS = stripslashes_array($HTTP_COOKIE_VARS);
$HTTP_POST_FILES = stripslashes_array($HTTP_POST_FILES);
$HTTP_ENV_VARS = stripslashes_array($HTTP_ENV_VARS);
if (isset($SESSION)) { #These are unconfirmed (?)
$SESSION = stripslashes_array($SESSION, '');
$HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, '');
}
/
The $GLOBALS array is also slash-encoded, but when all the above are
changed, $GLOBALS is updated to reflect those changes. (Therefore
$GLOBALS should never be modified directly). $GLOBALS also contains
infinite recursion, so it's dangerous...
/
}
function stripslashes_array($data) {
if (is_array($data)){
foreach ($data as $key => $value){
$data[$key] = stripslashes_array($value);
}
return $data;
}else{
return stripslashes($data);
}
}
?>