Tyler Roper
Tyler Roper

Reputation: 21672

The Best Method for Restricting Re-Voting

I'm making a site where users can post a "story" and then other members can upvote it. The question I have is regarding how to restrict people from upvoting multiple times. You do NOT need to sign-up to upvote.

These are my ideas, and if anyone could give me feedback about which would be best, or an idea of your own that would be better, it would be much appreciated.

  1. Have a table set up like this...
    • id - story ID
    • name - author
    • story - story
    • upvotes - number of upvotes
    • upvoter_ids - list of all unique ID's who have upvoted separated by a space. Unique ID is stored in a cookie on first visit. Upon revisit, pull all the IDs, explode them at the space, and see if there's a match.
  2. Create a new table just for votes, adding a row for every single vote.
    • voter_id - Unique ID stored in cookie
    • story_id - ID of story that was upvoted

Upvotes: 0

Views: 63

Answers (1)

Levi Botelho
Levi Botelho

Reputation: 25214

The cookie-based ID system is a fairly good one. If you aren't going to authenticate your users then you cannot absolutely prevent determined folks from voting again and again. But, if you aren't requiring people to vote then I am assuming that you accept that this kind of thing may happen from time to time.

The only change that I would make is to have a one-to-many relationship table with stories and upvote IDs. You can then query this table, filtering on story IDs to get the IDs of all those who upvoted. This is cleaner than exploding a space-delimited string.

Upvotes: 1

Related Questions