在ThinkPhp中通过SESSION实现了防止表单重复提交,实现方式如下:
<?php
session_start();
$_SESSION['__hash__'] = md5(microtime(true));
echo <<<EOT
<form action='a.php' method='post'>
<input type="text" value="{$_SESSION['__hash__']}" name="__hash__"/>
<input type="submit" value="login"/>
</form>
EOT;
?>
<?php
session_start();
$hash = $_REQUEST['__hash__'];
if($_SESSION['__hash__'] == $hash){
echo 'ok';
$_SESSION['__hash__'] = md5(microtime(true));
}else{
echo 'token error';
}
共有 0 条评论