比如要实现搜索用户名的功能,其实用户名是get过来的,用htmlspecialchars就够安全了吧?
htmlspecialchars(trim($_GET['username']), ENT_QUOTES);

解决方案 »

  1.   

    addslashes 处理(')、(")、(\)与 NULL
      

  2.   

    addslashes,魔术变量是开启的,自动会加上的吧。
      

  3.   

    其实你是要防sql注入吧。对于< php5.4.0 版本,当 get_magic_quotes_gpc() 开启时,get/post/cookie 提交过来的数据会自动转义, 不过 get_magic_quotes_gpc() 在php5.4.0 已经被移除了,永远返回false.因此,最安全的还是通过  mysql_real_escape_string() 来转义防止攻击数据库, 可以下面这样写就安全了:if (get_magic_quotes_gpc()) {
        $username= stripslashes($_GET['username']);
    }
    else {
        $username= $_GET['username'];
    }$username= mysql_real_escape_string($username);
    ...................................