check_admin_referer()

check_admin_referer()函数是Wordpress函数,通过验证用户是从另一个具有正确安全性的管理页引用的,来确保意图。

check_admin_referer( int|string $action = -1, string $query_arg = ‘_wpnonce’ )

说明(Description)

此功能确保用户打算执行给定的操作,这有助于防止点击劫持式攻击。它验证的是意图,而不是授权,因此它不验证用户的能力。这应该用当前的用户_can()或类似的方法执行。

如果nonce值无效,则函数将以“是否确定”退出风格信息。


参数(Parameters)

参数类型必填说明
$action(int | string)可选立即行动。
$query_arg(string)可选在$请求中检查nonce的键。

返回(Return)

(int|false)1如果nonce有效并在0-12小时前生成,2如果nonce有效并在12-24小时前生成。如果nonce无效,则为False。


源码(Source)

/**
 * Makes sure that a user was referred from another admin page.
 *
 * To avoid security exploits.
 *
 * @since 1.2.0
 *
 * @param int|string $action    Action nonce.
 * @param string     $query_arg Optional. Key to check for nonce in `$_REQUEST` (since 2.5).
 *                              Default '_wpnonce'.
 * @return false|int False if the nonce is invalid, 1 if the nonce is valid and generated between
 *                   0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
 */
function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) {
	if ( -1 == $action )
		_doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' );
	$adminurl = strtolower(admin_url());
	$referer = strtolower(wp_get_referer());
	$result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce($_REQUEST[$query_arg], $action) : false;
	/**
	 * Fires once the admin request has been validated or not.
	 *
	 * @since 1.5.1
	 *
	 * @param string    $action The nonce action.
	 * @param false|int $result False if the nonce is invalid, 1 if the nonce is valid and generated between
	 *                          0-12 hours ago, 2 if the nonce is valid and generated between 12-24 hours ago.
	 */
	do_action( 'check_admin_referer', $action, $result );
	if ( ! $result && ! ( -1 == $action && strpos( $referer, $adminurl ) === 0 ) ) {
		wp_nonce_ays( $action );
		die();
	}
	return $result;
}
endif;
if ( !function_exists('check_ajax_referer') ) :
更新版本源码位置使用被使用
2.5.0wp-includes/pluggable.php:1118128

笔记(Notes)

插件选项页中的用法
注意-过时用法

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索