title: Cookie based poll using PHP and AJAX
body: <p>On my website, I have a poll. It's cookie based poll. If a user votes, I create a cookie with the current poll, so he can't vote until a new poll is created. I know that the users can delete the cookies and vote again, but that is not the problem here.</p>
  
  <p>I have a ajax.php page that handles the ajax post. Here is the code:</p>
  
  <pre><code>if(isset($_COOKIE['poll_id']) &amp;&amp; $_COOKIE['poll_id'] == $poll_id)
  {
  // print message that it is already voted, show the results...
  }
  else
  {
  // update the database and create a cookie
  }
  </code></pre>
  
  <p>This code works OK if the the voting is made on button click. But, I started a javascript in Firebug that is doing this:</p>
  
  <pre><code>for(var i=0;i&lt;100;i++) {
      jQuery.post('ajax.php', {
          //post parameters
      });
  }
  </code></pre>
  
  <p>And I get 100 votes. If i run the script again, it fails, because a cookie is created, but it seems that if I make a 100 simultaneous requests, the check fails, because I guess the system doesn't have the time to create the cookie in time, so all the updates goes through.</p>
  
  <p>Any suggestions on how to solve this?</p>