I have a web poll that I would like my visitors to only take once. I think I understand the logic but don't know where to start with the code. Here is what I am thinking:

  1. User clicks on a link to get to the form
  2. A cookie is set on the users computer
  3. User takes the poll
  4. If users try to come back again and take the poll a second time
  5. The cookie checks against itself so see if the visitors already came
  6. Print out some sort of message like "Um, sorry but you can only take this poll once"
  7. Web poll doesn't display again.

My JS is a little rusty but I can follow along. The part I'm getting stumped on is setting the cookie and having it check itself.

P.S. Or if there is a better way, please let me know

If this poll is for registered users only, a better way would be to handle the voting part at the server side wherein an entry would be placed in the database against the users' name and be checked for each vote request so that he can vote only once.

If this poll is for all users of your site, cookies seem to be your best bet; though beware that if cookies / javascript are disabled, it can cause serious statistical issues. One way to avoid this would be to make the 'Post a Poll' button Javascript enabled and do a check whether cookies are enabled which disables the post a poll option for users who have javascript / cookies turned off.

BTW, all you need to know about browser cookies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.