【发布时间】:2018-06-18 08:21:09
【问题描述】:
关注https://codeutopia.net/blog/2008/10/16/how-to-csrf-protect-all-your-forms/的帖子
我正在尝试将代码添加到 formtoemailpro.php https://formtoemail.com/developer_pricing.php
我将密钥生成器添加到表单页面:
//Generate a key, print a form:
$key = sha1(microtime());
$_SESSION['csrf'] = $key;
还有隐藏字段:
<input type="hidden" name="csrf" value="<?php echo $key; ?>" />
但我无法将以下内容添加到 formtoemailpro.php 并使其正常工作。我已将上半部分放在表单的顶部,将“}”放在底部,并添加了“if(!isset”表达式以及表单处理部分的其他类似元素,但我失败了。
if($_SERVER['REQUEST_METHOD'] == 'POST')
//Here we parse the form
if(!isset($_SESSION['csrf']) || $_SESSION['csrf'] !== $_POST['csrf'])
throw new RuntimeException('CSRF attack');
//Do the rest of the processing here
}
我很抱歉我的无知,请任何人帮助我吗?
谢谢。
【问题讨论】:
-
在
if之前显示$_POST['csrf']的值和$_SESSION['csrf']的值,你就明白问题出在哪里了