php通过session防url攻击方法

yipeiwu_com6年前PHP代码库

本文实例讲述了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']) 

/* 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程序设计有所帮助。

相关文章

php获取本地图片文件并生成xml文件输出具体思路

复制代码 代码如下: <?php $dir="upload/"; $dir_res=opendir($dir); $fileFormat=array(0=>".jpg",1=...

PHP之生成GIF动画的实现方法

代码如下所示:复制代码 代码如下:<?class GifMerge {     var $ver    &nb...

PHP根据IP判断地区名信息的示例代码

看代码 复制代码 代码如下: <?php header("Content-type: text/html; charset=utf-8"); function getIP(){ i...

Ubuntu server 11.04安装memcache及php使用memcache来存储session的方法

本文实例讲述了Ubuntu server 11.04安装memcache及php使用memcache来存储session的方法。分享给大家供大家参考,具体如下: 1、首先安装memcac...

PHP正则匹配反斜杠'\'和美元'$'的方法

本文实例讲述了PHP正则匹配反斜杠'\'和美元'$'的方法。分享给大家供大家参考,具体如下: 1. test.php: <?php $content = '111111...