I’m using jQuery for users voting articles up/down. When the user votes a cookie is set so the user can only vote an article once (without refreshing cookies). This works fine, except when the user votes and refreshes the page instantly after voting:
jQuery:
$.post('vote.php',{id:id,field:field},function(){
// change button graphics
});
PHP:
setcookie(User::$cookieStart . User::$db_fields[$field_index],
$cookie . ':' . $id, time()+60*60*24*30,'/');
// This calls a function that effects the db
User::actionArticleTable($id,$field_index,1);
When the user refreshes, the cookie is not set but the mysql-info is changed, even though the db code is after the cookie code.
Cookies are just header items in HTML pages, so no change in cookies occurs until the vote.php page is loaded. If the user refreshes the main page before the vote.php page has returned no cookie is set. The cookie is fine for next time users comes on this page, but if you want to block the voting instantly consider setting the cookie by javascript.