<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
//error_reporting(E_ALL);
set_magic_quotes_runtime(0);
// Be paranoid with passed vars
if (@ini_get('register_globals')) {
foreach ($_REQUEST as $var_name => $void) {
unset(${$var_name});
}
}
?>
上面这些,是一些基本的设置,包括错误提示级别。如果你的php.ini中打开了register_globals(它常会带来危险并使人感到困惑),我们要把它随便设置的那些全局变量删掉。error_reporting(E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
//error_reporting(E_ALL);
set_magic_quotes_runtime(0);
// Be paranoid with passed vars
if (@ini_get('register_globals')) {
foreach ($_REQUEST as $var_name => $void) {
unset(${$var_name});
}
}
?>
<?php
if (!get_magic_quotes_gpc()) {
if (is_array($_GET)) {
while (list($k, $v) = each($_GET)) {
if (is_array($_GET[$k])) {
while (list($k2, $v2) = each($_GET[$k])) {
$_GET[$k][$k2] = addslashes($v2);
}
@reset($_GET[$k]);
}
else {
$_GET[$k] = addslashes($v);
}
}
@reset($_GET);
}
if (is_array($_POST)) {
while (list($k, $v) = each($_POST)) {
if (is_array($_POST[$k])) {
while (list($k2, $v2) = each($_POST[$k])) {
$_POST[$k][$k2] = addslashes($v2);
}
@reset($_POST[$k]);
}
else {
$_POST[$k] = addslashes($v);
}
}
@reset($_POST);
}
if (is_array($_COOKIE)) {
while (list($k, $v) = each($_COOKIE)) {
if (is_array($_COOKIE[$k])) {
while (list($k2, $v2) = each($_COOKIE[$k])) {
$_COOKIE[$k][$k2] = addslashes($v2);
}
@reset($_COOKIE[$k]);
}
else {
$_COOKIE[$k] = addslashes($v);
}
}
@reset($_COOKIE);
}
}
define('STRIP', (get_magic_quotes_gpc()) ? true : false);
上面的一陀,显而易见,它在做转义过滤所有来自客户端的输入。
