php通过session防url攻击方法
本文实例讲述了php通过session防url攻击方法。分享给大家供大家参考。具体实现方法如下:
通过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'])
{
/*UpdatePassword*/
mail($clean['email'],'YourNewPassword',$new_password);
}
}
?>使用时URL可设置如下:
http://example.org/reset.php?user=php&email=chris%40example.org
如果reset.php信任了用户提供的这些信息,这就是一个语义URL攻击漏洞,在此情况下,系统将会为php帐号产生一个新密码并发送至chris@example.org,这样chris成功地窃取了php帐号.
希望本文所述对大家的PHP程序设计有所帮助。
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语