WordPress函数文档check_admin_referer()

校验某个验证信息 描述 Tests either if the current request carries…

校验某个验证信息

描述

Tests either if the current request carries a valid nonce, or if the current request was referred from an administration screen; depending on whether the $action argument is given (which is prefered), or not, respectively. On failure, the function dies after calling the wp_nonce_ays() function.

Used to avoid security exploits.

The now improper name of the function is kept for backward compatibility and has origin in previous WordPress versions where the function only checked the referer. For details, see the Notes section below.

用法

Obsolete Usage

<?php check_admin_referer(); ?>

Prefered Usage

<?php check_admin_referer$action$query_arg ); ?>

参数

$action

(string) (可选) Action name. Should give the context to what is taking place. (Since 2.0.1).

默认值: -1

$query_arg

(string) (可选) Where to look for nonce in the $_REQUEST PHP variable. (Since 2.5).

默认值: ‘_wpnonce’

示例

Obsolete usage here (script dies if the admin referer is not validated).

Here is an example of how you might use this in a plugin’s option page. You add a nonce to a form using the wp_nonce_field() function:

Then in the page where the form submits to, you can verify whether or not the form was submitted and update values if it was successfully submitted:

注意

  • Using the function without the $action argument is obsolete and, as of Version 3.2, if WP_DEBUG is set to true will die with an appropriate message (“You should specify a nonce 动作 to be verified by using the first parameter.” is the default).
  • As of 2.0.1, the referer is checked only if the $action argument is not specified (or set to the default -1) as a backward compatibility fallback for not using a nonce. A nonce is prefered to unreliable referers and with $action specified the function behaves the same way as wp_verify_nonce() except that it dies after calling wp_nonce_ays() if the nonce is not valid or was not sent.

历史

添加于 版本: 1.2.0

源文件

check_admin_referer() 函数的代码位于 wp-includes/pluggable.php.

相关

Nonce functions: wp_explain_nonce(),
wp_nonce_ays(),
wp_nonce_field(),
wp_nonce_url(),
wp_verify_nonce(),
wp_create_nonce(),
check_admin_referer(),
check_ajax_referer(),
wp_referer_field()

Nonce hooks: nonce_life, nonce_user_logged_out, explain_nonce_(verb)-(noun), check_admin_referer

  • WordPress Nonce Implementation

Resources

  • PHP: die – Manual
  • PHP: $_REQUEST – Manual
  • Mark Jaquith – WordPress Nonces
  • Vladimir Prelovac – Using Nonces in WordPress Plugins
  • Cryptographic nonce – Wikipedia, the free encyclopedia
  • wp_verify_nonce vs check_admin_referer – WordPress Answers
  • 原文:http://codex.wordpress.org/Function_Reference/check_admin_referer
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT