文档介绍:小心自己被攻击:
攻击
①$sql="select * from users where username='$username' and password='$password'";
万能密码:aa’or 1=’1
$sql="select * from users where username='$username' and password=' aa’or 1=’1'";
万能用户名:xx’ union select * from users/*
$sql="select * from users where username=' xx’ union select * from users/*' and password='$password'";
②$sql="select * from users where username=$username and password=$password";
Mysql会把输入当做数值对待。
万能密码:用户名随便前些一个数字,密码用这个:56 union select * from users;
万能用户名:56 union select * from users/* 密码随便输入
防守:
服务器防范:在服务器端配置:magic_quotes_gpc设置为on,
第一种攻击就会失效。如果我们的magic_quotes_gpc设置为on,服务器就会对所有的‘加入转义\’,name=’123’,则会变为:\
’123\’;
第二种攻击仍然会生效。因为攻击中无‘的存在。高手会用char()去修改
代码防范:
常用的方案:
密码比对:
思想是通过用户输入的用户名去查询数据库,如果查到了用户所对应的密码,则和用户输入的密码进行不对,相同则说明该用户合法。不同则不合法。
pdo方式
php data object
相当于数据库的抽象层
启用pdo,
别让他人成为你的超级管理员: