如果您有一个允许用户添加注释的项目,那么如何传递用户正在回复的项目?
我虽然在表单中使用隐藏字段,但是可以使用诸如firebug之类的插件轻松更改:
<form method="post" action="blah">
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">
<!-- other form data here -->
<input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
或者只是简单地使用会话:
$_SESSION['item_id'] = $item_id
Run Code Online (Sandbox Code Playgroud)
有没有一种安全的方式来发送表单中的项目数据?
编辑: 这是在验证后,...我实现了一些XSS保护(形式令牌等).我问的原因只是要知道最佳做法是什么.
我虽然做了类似的事情
$_SESSION['item_id'] = $id //this is set when they visit the current item
Run Code Online (Sandbox Code Playgroud)
然后在表单中有一个隐藏的字段:
<input type="hidden" name="item_id" value="<?php echo $id?>">
Run Code Online (Sandbox Code Playgroud)
最后检查会话是否与点击的id匹配:
if ($_SESSION('item_id') !== $item_id) //the value posted in the form
{
die('There\'s got to be a morning after
If we can hold on through the night …Run Code Online (Sandbox Code Playgroud)