admin管理员组

文章数量:1391987

I created the nonce when I localize a script file:

wp_localize_script('cad-search', 'cad_ajax', 
    array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
         'nonce'=> wp_create_nonce('cad_nonce'))
); 

wp_enqueue_script('cad-search');

But when the nonce is evaluated in the function called through AJAX the values are not the same:

if ( !wp_verify_nonce( $_POST['nonce'], 'cad_nonce')) {
    exit('Missing nonce! Please refresh the page.');
} 

This code works in Firefox but not in Chrome.

I created the nonce when I localize a script file:

wp_localize_script('cad-search', 'cad_ajax', 
    array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
         'nonce'=> wp_create_nonce('cad_nonce'))
); 

wp_enqueue_script('cad-search');

But when the nonce is evaluated in the function called through AJAX the values are not the same:

if ( !wp_verify_nonce( $_POST['nonce'], 'cad_nonce')) {
    exit('Missing nonce! Please refresh the page.');
} 

This code works in Firefox but not in Chrome.

Share Improve this question asked Feb 18, 2020 at 18:31 AlanPAlanP 7211 gold badge9 silver badges21 bronze badges 2
  • Does Chrome cache the page? – kero Commented Feb 18, 2020 at 18:34
  • That could be a possibility since it is only happening on the front end. If so, what can be done about it? Caching would make nonces impossible to use. – AlanP Commented Feb 18, 2020 at 18:57
Add a comment  | 

1 Answer 1

Reset to default 0

Turning off a cache plugin, Fast Cache in this case, and adding 'define('WP_CACHE', false);' to the wp-config.php file seems to have resolved this issue.

本文标签: Why are nonces working in Firefox but not in Chrome