某开源项目中的反SQL注入代码片段

没事看看开源的项目,也能有些收获。比如有些模块几乎是所有项目都要用到的,如反SQL注入处理等。

今天看EasyTalk的源码,这是他们的处理方式,可以参考一下

//addslashes() 函数在指定的预定义字符前添加反斜杠
function daddslashes($string) {
    $string=str_replace(”‘”,’”‘,$string);
    !defined(’MAGIC_QUOTES_GPC’) && define(’MAGIC_QUOTES_GPC’, get_magic_quotes_gpc());
    if(!MAGIC_QUOTES_GPC) {
        if(is_array($string)) {
            foreach($string as $key => $val) {
                $string[$key] = daddslashes($val);
            }
        } else {
            $string = addslashes($string);
        }
    }
 return $string;
}

其实就是addslashes转义’ 引号。此外,htmlspecialchar经常被用来防止用户输入恶意script脚本

Posted in 未分类 at 07月 15th, 2009. Trackback URI: trackback
Tags: ,

No Responses to “某开源项目中的反SQL注入代码片段”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
请输入图片中的字符以验证你并非垃圾机器人. 点击图片收听验证码的语音版.
点击这里收听此验证码的语音版本