Possible Duplicate:
PHP: the ultimate clean/secure function
在我插入一个用户时,我就采用了这一守则:
function RegisterUser($userName, $pass, $email, $reputation, $role, $ban, $date, $ip, $numberAttempts, avatar)// anonym , false , $myDate,$ip, 0,
{
$userName= SanitizeString($userName);
$pass= SanitizeString($pass);
$email= SanitizeString($email);
$userName=mysql_real_escape_string($userName);
$pass=mysql_real_escape_string($pass);
$email=mysql_real_escape_string($email);
The sanitize function is the following:
function SanitizeString($var)
{
//$var=stripslashes($var);
$var=htmlentities($var, ENT_QUOTES, UTF-8 );
$var=strip_tags($var);
return $var;
}
我指的是保护自己免遭恶意攻击的正确途径(Xss攻击、javascript攻击、 sql注射)。