该信息内容可能包括 “ ‘ 空格 特殊符号
例如 “ user‘’‘’abc”
$_POST[‘pass’] =” “” and (select * from tbl_usr)”
防注入(攻击)
在用户执行注册过程中口令内容部分使用了类似
(select insert update delete and or etc.)
eregi(“正则表达式”,“判断字符串”,$name);
eregi($pattern ,)
$pattern=(select|insert|update)
Addslashes()
\ :转义字符
1、 php
1、 register_glabals=off|on
$_POST[‘name’]
$name
2、 SQL语句尽量不要省略引号
3、 $_POST(GET COOKIE )过滤后在接受
4、 命名数据库
5、 尽量封装方法,避免暴露
6、 重定向
考虑:web项目有多少,
过滤过程写成函数单独存成一个文件function check_form($form){
get_magic_quotes_gpc(void) 获取php.ini中magic_quotes_gpc的状态
magic_quotes_gpc=on get_magic_quotes_gpc() 返回值为true
magic_quotes_gpc=off get_magic_quotes_gpc() 返回值为false
判断当前的环境中的php.ini的magic_quotes_gpc()的状态
if(!get_magic_quotes_gpc()){
//如果开启开关,对用户输入的变量进行addslashes()处理
//该函数被引入到的文件中表单里的input标签不确定,用循环方式
for($i=0;$i<count($form);$i++){
$form[$i]=addslashes($form[$i]);
}
将过滤后的纯字符串return
纯粹的字符串要求写入数据表
需要将多余一个的信息传递到函数外部;
第一种:组成字符串
第二种:组成数组
}
return $form;
}
验证码
设计表
Username password 。。 status md5name
Zhangsan 123456 0
登录
Name password status=1
http://localhost/test.php?name=……
name=ziduan
update status=1
PHP防SQL注入技巧
42万+

被折叠的 条评论
为什么被折叠?



