欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

防止SQL注入

程序员文章站 2022-07-23 20:15:50
大概分两步,先自定义字符串规则如去除空格特殊符号等等,再使用转义,后面的语句一定要加上单引号。 ......
 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 }

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