Unique IPs in a voting system
The Unobtainably-Perfect: (Unique Govt Number)
- User votes using a verifiable unique identifier like a social-security or passport number
The Close-Enough-For-Reality: (Email/3rd Party Auth)
- user registers an account with an email address and password (or google/facebook)
- 1 email address = 1 vote
- Users can't clear cookies and get extra votes, App doesn't shut 1000's out with shared IPs
The Good-Thought-But-False-Pretense (IP addresses)
- Office buildings: 1000's of users on the same external IP get shut-out
- Universites: Connect to wireless in classroom. Vote. Move to next classroom. Reconnect and vote again
The Crash-And-Burn (Cookies)
- Vote
- ctrl shft del enter
- vote
- repeat
Limit 1 vote per IP Address?
I would suggest not going with the IP approach. When I looked at this before some of your large ISPs reuse IPs a lot (AOL...), but if you do use IP addresses, use a database to track them. A fast way to do it is to make it a unique key and to catch the exception as "already voted".
One good thing to add is not to show a user that their vote was not counted, just show the results, or thank them for voting. By not giving that specific error, it is harder and sometimes not even noticed by your problem users.
Database structure for voting system with up- and down votes
Regarding the comments, we found the solution that best fits to Zardoz
He does not want to always count votes and needs as much details as possible. So the solution is a mix of both.
- Adding an integer field in the considered table to store vote counts (make sure there won't be overflows).
- Create additional tables to log the votes (user, post, date, up/down, etc.)
I would recommend to use triggers to automatically update the 'vote count field' when inserting/deleting/updating a vote in the log table.
Related Topics
Mysql_Fetch_Assoc(): Supplied Argument Is Not a Valid MySQL Result Resource in PHP
How to Set Time Zone in Codeigniter
Type-Juggling and (Strict) Greater/Lesser-Than Comparisons in PHP
Generating a Single Entity from Existing Database Using Symfony2 and Doctrine
What Is an Abstract Class in PHP
Autoload Classes from Different Folders
Adding Subscribers to a List Using Mailchimp's API V3
Laravel 5.2 Not Reading Env File
Find First Character That Is Different Between Two Strings
Programmatically Add Product to Cart with Price Change
Can PHP's Glob() Be Made to Find Files in a Case Insensitive Manner
Convert Jpg/Gif Image to Png in PHP
How to Allow Duplicate Keys in PHP Array
Why Doesn't Var_Dump Work with Domdocument Objects, While Print($Dom->Savehtml()) Does