<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="php跨站攻击的原理与防范技巧及token实例分析" id="card1">
<p> 游客</p><p>
标题:php跨站攻击的原理与防范技巧及token实例分析<br/>
正文:<br/>
跨站攻击就是利用程序上的一些细节或bug问题进行的，那么我们要如何耿防止跨站攻击呢？下面就以一个防止跨站攻击例子来说明，希望对各位有帮助。代码如下:&amp;lt;?php #demo for prevent csrf /** * enc */ function encrypt($token_time) { return md5('!@##$@$$#%43' . $token_time); } $token_time = time(); $token = encrypt($token_time); $expire_time = 10; if ($_POST) { $_token_time = $_POST['token_time']; $_token = $_POST['token']; if ((time() &amp;ndash; $_token_time) &amp;gt; $expire_time) { echo &amp;quot;expired token&amp;quot;; echo &amp;ldquo;&amp;lt;br /&amp;gt;&amp;rdquo;; } echo $_token; echo &amp;quot;&amp;lt;br /&amp;gt;&amp;quot;; $_token_real = encrypt($_token_time); echo $_token_real; //compare $_token and $_token_real } ?&amp;gt; &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;meta http-equiv=&amp;quot;content-type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt; &amp;lt;title&amp;gt;test for csrf - camnpr&amp;lt;/title&amp;gt; &amp;lt;meta http-equiv=&amp;quot;&amp;quot; content=&amp;quot;&amp;quot; /&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;form method=&amp;quot;post&amp;quot; action=&amp;quot;&amp;quot;&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;text&amp;qu<br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2020&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2020&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2020&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=2020&amp;Page=2">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=2020">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=2020">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>