PHP是否有自己版本的Rails真实性令牌?
<meta name="csrf-token" content="<%= form_authenticity_token %>" />
<meta name="csrf-param" content="authenticity_token" />
如果没有,实现相同功能的最佳方法是什么?
答案 0 :(得分:8)
输出到表格时:
$token = md5(time() . rand(1,100));
$_SESSION['token'] = $token;
<input type='hidden' name='token' value='<?=$token;?>'/>
POST后:
if(empty($_POST['token']) || $_POST['token'] !== $_SESSION['token']){
exit("Bad token!");
}
unset($_SESSION['token']);