我有一个应该是安全的应用程序,因此使用了Nonce,但是我无法使它们正常工作。我尝试了几种方法,但由于验证不起作用,显然缺少了一些内容。
我的js代码片段是:
function placeNew(next){
_nonce = $('input#_nonce').val();
request = $.ajax({
type: 'POST',
url: url_path + '/foo/v1/newbee',
data: {bid : next , _nonce : _nonce},
security: '<?php echo wp_create_nonce( "a" ); ?>',
dataType: 'json'
});
request.done(function (response, textStatus, jqXHR){
str = JSON.stringify(response);
if(response["error"]){
alert(response["message"]);
}
Run Code Online (Sandbox Code Playgroud)
使用以下代码将现时值添加到页面:
$nonce = wp_create_nonce( 'a' );
echo "<input type='hidden' id='_nonce' value=" . $nonce ."/>";
Run Code Online (Sandbox Code Playgroud)
在php中,以下函数片段用于获取和比较随机数:
function ace($request) {
global $wpdb;
$timestamp = time();
$nonce = (string) $request['_nonce'];
$verify = check_ajax_referer( 'a', $nonce, false );
if ( …Run Code Online (Sandbox Code Playgroud)