开发者

How to remember a action from a user(Like them thumbing or star rating)?

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 wha开发者_JAVA技巧t. 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.


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.


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜