当前位置: 移动技术网 > IT编程>数据库>Mysql > 防止SQL注入

防止SQL注入

2018年02月11日  | 移动技术网IT编程  | 我要评论
大概分两步,先自定义字符串规则如去除空格特殊符号等等,再使用转义,后面的语句一定要加上单引号。 ...
 1 function checkStr($username){
 2         //自定义字符串规则
 3 } 
 4 
 5 function checkLogin($username,$password){
 6         
 7         $password = md5($password);
 8 
 9         $username = addslashes($username);//转义
10 
11         $sql = "select * from {$this->getTableName()} where u_username='{$username}' and u_password='{$password}'";
12 
13         return $this->db_getRow($sql);
14 }

大概分两步,先自定义字符串规则如去除空格特殊符号等等,再使用转义,后面的语句一定要加上单引号。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网