I have many polls on my site, and I want to prevent users from re-voting many times. As far as I know, I can either keep a IP log of visitors, or store cookies. I tried using an IP log into mySQL database, but theres one problem: All visitors behind a router have the same external IP so only one person behind the router can vote on a certain poll.
So now I'm switching my code to use cookies unless there are better solutions. Since there will eventually be hundreds or thousands of polls, and I 开发者_运维问答think there is a 20 cookie limit, how can I store values for each poll? The values can just be binary values, for example poll1=0 if not yet voted, poll1=1 if voted.
Also, if it helps, each poll immediately shows the results using jquery. I'm assuming I can set/modify the cookie in the jquery resonse.
Any ideas? Thanks! (btw, I realize cookies can be deleted)
If you really want to restrict per-user, you need to implement user identification, which means you need user registration, login and session management. Once you have that, it's not at all difficult. Just implement a many-to-many relation between your user records and your poll records with a join record created when a user takes a poll and checked to determine whether they've already taken it.
Trying to implement a limit on the activities of users without implementing a way of really identifying users will never work well.
Even though you may have hundreds of polls, it is reasonable to expect that each user will only vote in a few of those. So you can just have a single cookie with a comma-separated list of poll IDs in which the user has voted.
Of course, cookies don't provide any sort of protection since they can be deleted or tampered with, but they are also the only practical way to store such information and they work well in most cases.
精彩评论