views:

57

answers:

3

Hi

I am just wondering on how sites do "ratings" or "thumbs up".

I figured that each of the thumbs up would have a special id that would correspond to some value in the database that would store the total count.

However what I am unsure of is how people make it the user can only click on it one. Like if hit thumbs up they can't keep spamming it.

I am not sure if they write it too a cookie or what. It seems like most of the site will have it so that even if you load up a different browser you can't go to the same post and thumbs it up.

+1  A: 

Some do cookies, others remember your IP-address.

The former can be beaten by erasing cookies, while the latter doesn't work correctly with NAT: if there are many people behind NAT (think corporate buildings, or campuses, or internet-cafes), only one of those people can vote.

Fyodor Soikin
later also won't work if that is Dynamic IP Address
Umair Ashraf
A: 

You're right about the ID and the database bit. Most sites (even this one) will allow this sort of functionality when the user is logged-in. Sure, abusers could register to the site a number of times, but that raises the "cost" for abusers to do their abuse.

Some sites will allow this without the user being logged-in, but they are still getting a session. Their session will often be logged with the IP address and in many cases a 'browser signature'. If the user then comes back with the same browser and IP address, then subsequent votes may be ignored, or they will replace any previous.

I hope this gets you pointed in the right direction!

mkoistinen
A: 

You need 3 table

Users Questions Votes

Having Votes a composed primary key (userID, questionID) you can assure you will only have one vote per user. If the tuple (UserID, questionID) already exists just discard the query.

Now, if you're talking about non-registered users it follows the same logic, only using the user IP (with some other optional information, like the browser's footprint) instead of the userID.

For non-registered users cookies add that extra layer of protection you need but they're not mandatory.

Ben
So basically you store it all in the table and every time the page loads up you check either by userId or IP to figure out if to disable the voting?
chobo2
@chobo basically, yes.
Ben