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
1 Answer
Reset to default 0Turning 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.