2015-03-02 62 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