2015-03-02 60 views
0

我有意见这个WordPress的形式,这是非常标准:是wordpress评论表单安全吗?

<form action="http://sitename.com/wp-comments-post.php" target="writeIframe" method="post" id="commentform" class="comment-form"> 
    <p class="comment-form-author"> 
     <label for="author">Your name</label> 
     <input id="author" name="author" type="text" value="" size="30"> 
    </p> 
    <p class="comment-form-comment"> 
     <label for="comment">Comment</label> 
     <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea> 
    </p> 
    <p class="form-submit"> 
     <input name="submit" type="submit" id="submit" class="submit" value="Send"> 
     <input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID"> 
     <input type="hidden" name="comment_parent" id="comment_parent" value="0"> 
    </p> 
</form> 

它发出了一个隐藏的iframe内的用户输入数据到WP-评论-post.php中。这是安全的开箱即用Wordpress还是我应该添加代码来防止通过我的评论表单进行攻击?

回答

1

你看看使用wp_nonce_field()。

这里是WordPress的抄本说:

随机数是为了帮助保护的URL和形式由某些类型的滥用的“使用一次的数字”。

所以我一定建议你看看它并使用它。 回到这个抄本页面了解更多:

http://codex.wordpress.org/WordPress_Nonces#Adding_a_nonce_to_a_form

务必阅读添加一个随机数以一种形式部分

+0

所以我把下面的第一场在我的形式是这样的:

<?php wp_nonce_field('my_nonce_action','my_nonce_name'); ?> 等 – 2015-03-02 14:31:41

+0

是的,你也应该确保你正在验证nonce。您应该使用此代码验证您的随机数:if( !isset($ _POST ['my_nonce_name'])||!wp_verify_nonce($ _POST ['my_nonce_name']'my_nonce_action'){print'Sorry,your nonce没有核实。';出口; } else {//你的代码验证成功} – MMK 2015-03-02 15:58:14

+0

这样做,在我的comments.php文件的顶部? $ retrieve_nonce = $ _REQUEST ['_ wpnonce'];如果(!wp_verify_nonce($ retrieve_nonce))死('失败的安全检查'); – 2015-03-03 13:54:45