php中的url攻击怎么利用session来防止

本篇文章为大家展示了php中的url攻击怎么利用session来防止,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

通过session跟踪,可以很方便地避免url攻击的发生,php采用session防url攻击方法代码如下:

<?php 
session_start();  
$clean = array();  
$email_pattern = '/^[^@s<&>]+@([-a-z0-9]+.)+[a-z]{2,}$/i';  
if (preg_match($email_pattern, $_POST['email']))  
{
$clean['email'] = $_POST['email'];  
$user = $_SESSION['user'];  
$new_password = md5(uniqid(rand(), TRUE));  
if ($_SESSION['verified'])  
{  
/* Update Password */  
mail($clean['email'], 'Your New Password', $new_password);  
}  
}  
?>

使用时URL可设置如下:
http://example.org/reset.php?user=php&email=chris%40example.org

如果reset.php信任了用户提供的这些信息,这就是一个语义URL 攻击漏洞,在此情况下,系统将会为php 帐号产生一个新密码并发送至chris@example.org,这样chris 成功地窃取了php 帐号.

上述内容就是php中的url攻击怎么利用session来防止,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。