学习php安全和防注入

来源:互联网 发布:邮箱注册知乎怎么登陆 编辑:程序博客网 时间:2024/04/30 07:23

大致有:

1. SQL注入防范

2. 文件上传漏洞防范

3. cookie欺骗防范

4. 跨站攻击(XSS)防范

主要介绍下面2个函数的使用:

<?php

//增加转义:
if (!get_magic_quotes_gpc())
{
function addslashes_deep($value)
{
if(is_array($value))
$value=array_map('stripcslashes_deep',$value);
else
$value=addslashes($value);
return $value; 
}
//用上面的函数stripcslashes_deep递归增加所有参数里面的转义符号“\”
$_POST = array_map('addslashes_deep',$_POST); 
$_GET = array_map('addslashes_deep',$_GET); 
$_COOKIE = array_map('addslashes_deep',$_COOKIE); 

}

//去掉转义:
if (!get_magic_quotes_gpc())
{
function stripcslashes_deep($value)
{
if(is_array($value))
$value=array_map('stripcslashes_deep',$value);
else
$value=stripcslashes($value);
 return $value; 
}
//用上面的函数stripslashes_deep递归增加所有参数里面的转义符号“\”
$_POST = array_map('stripcslashes_deep',$_POST); 
$_GET = array_map('stripcslashes_deep',$_GET); 
$_COOKIE = array_map('stripcslashes_deep',$_COOKIE); 
}

?> 

总结:

1.永远不要相信你的用户。
2.Fliter input,Escape output.