Home  >  Article  >  Backend Development  >  偶然关注数据库安全有关问题,如下

偶然关注数据库安全有关问题,如下

WBOY
WBOYOriginal
2016-06-13 13:37:571158browse

偶然关注数据库安全问题,如下
一张表 id字段为主键 自增

如果要删除某条数据

那么

"delete from test where id=".$_POST['id']

问题就是有没有可能这样是不安全的

"delete from test where id=".$_POST['id']

$_POST['id'] = 2 or 1=1 之类的情况

会产生这种情况吗,导致全部删除

------解决方案--------------------
有啊,所以一般对数值类型也加引号
"delete from test where id='$_POST[id]'"
------解决方案--------------------
有可能。这就是常常说的防sql注入。转义特殊字符。
------解决方案--------------------
加引号后只要有转义处理就无可能
------解决方案--------------------
intval
------解决方案--------------------
方法一:在php.ini中设置:magic_quotes_gpc = Off 

方法二: $str=stripcslashes($str)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn