admin管理员组文章数量:1125609
I am new in using Nonce.I am using Nonce like below in a Form
wp_nonce_field('add_new_addres','add_new_address');
I am trying to verify Nonce like below
if(isset( $_REQUEST['action'] ) && ('newAddress' === $_REQUEST['action']) && (wp_verify_nonce($_REQUEST['add_new_address'], 'add_new_addres'))) {
//more code here
}else {
//more code here
}
else
block is executing but I need to execute if
block.
I am new in using Nonce.I am using Nonce like below in a Form
wp_nonce_field('add_new_addres','add_new_address');
I am trying to verify Nonce like below
if(isset( $_REQUEST['action'] ) && ('newAddress' === $_REQUEST['action']) && (wp_verify_nonce($_REQUEST['add_new_address'], 'add_new_addres'))) {
//more code here
}else {
//more code here
}
else
block is executing but I need to execute if
block.
1 Answer
Reset to default 3Problem is, you are submitting data as POST data, but verifying nonce from GET data.
Here is how you can create a nonce field in a form easily:
wp_nonce_field( 'add_new_addres' );
Actually, I personally don't use more than 1 parameter when calling the wp_nonce_field
function.
Then when verify use the following code:
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'add_new_addres' ) ) {
wp_die( 'Are you cheating?' );
// Anything that you want to display for unauthorized action
}
// Good to go for next step
本文标签: Verify a nonce in Form submission
版权声明:本文标题:Verify a nonce in Form submission 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736669475a1946839.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论