Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:53:48+00:00 2026-06-13T10:53:48+00:00

On my website, I have a poll. It’s cookie based poll. If a user

  • 0

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.

I have a ajax.php page that handles the ajax post. Here is the code:

if(isset($_COOKIE['poll_id']) && $_COOKIE['poll_id'] == $poll_id)
{
// print message that it is already voted, show the results...
}
else
{
// update the database and create a cookie
}

This code works OK if the the voting is made on button click. But, I started a javascript in Firebug that is doing this:

for(var i=0;i<100;i++) {
    jQuery.post('ajax.php', {
        //post parameters
    });
}

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.

Any suggestions on how to solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:53:49+00:00Added an answer on June 13, 2026 at 10:53 am

    This is where XSRF comes to play. In your site you should first create a random (properly salted and enoughly secure) string and store it in session. In all your pages you should be getting this session value and passing it with form submits. When examining user input you should be checking this value as part of the page request.

    Now if in the poll page you are sending this, and in ajax.php you are examining this then you will find that value and know that this is a safe request. When someone tries something smart over firebug/jquery etc, they will not be able to access/send this value, and your pages can ignore such requests.

    Of course, my explanation is an oversimplification for better/easier understanding. But do read more about it, that will help solve your scenario as well as make your code more robust.

    Adding a simple pseudo code example:

    Assume first your random XSRF string is already set in session.

    jQuery.post('ajax.php', {
         <?php echo $_SESSION['token'];?>,
        //rest of the post parameters
    });
    

    Now when someone tries it with firebug:

    for(var i=0;i<100;i++) {
        jQuery.post('ajax.php', {
            //post parameters
            //cannot access $_SESSION['token'] so cannot pass it..
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have website based on Umbraco 5. I have installed contact form plugin (http://cultivjupitercontact.codeplex.com/).
I have website where users can login with their Facebook account. I am using
On a website I have implemented the login using OpenID (based on StackOverflow). But
So basically I have website that has names of cities that can be checked
I have been developing a nodejs server to provide server-side-events for a new website
I have a website that has a voting poll module. A poll controller accepts
I have created a DNN module for a Poll. This module is created as
I have website where a user selects a certain criteria for finding another user
We have website with adult content. If user visit site first time, we need
I have a website where I need to poll a webpage in every minute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.