I’ve some trouble getting nonces working with my ajax submit form.
First of all i create a nonce and pass it to my registered script, i’ll later send it to ajax-handler packed with my form fields:
wp_localize_script( 'roll_script', 'Roll', array(
'postRollNonce' => wp_create_nonce('nonce-roll')));
In my ajax-response handler i verify the nonce, do my stuff and try to create a new nonce to send back to js, for later submit:
function on_ajax_roll(){
if (!wp_verify_nonce($_POST['postRollNonce'], 'nonce-roll' )) die ('No allowed!');
// nonce is valid! do some stuff...
$r = array('postRollNonce' => wp_create_nonce('nonce-roll'));
$response = json_encode($r);
header( "Content-Type: application/json" );
echo $response;
die();
}
…but, back to my js, the new nonce is exactly the same as the old one! Since nonce is supposed to change with time, why a second call to wp_create_nonce return the same string?