views:

84

answers:

4

in my application a user can post his/her article that other users can response upon ans vote up and down also like stackoverflow has for posted question ans answers.

How can I restrict user so that he/she can't vote twice ?

+1  A: 

You will need to use some kind of server side scripting to remember users by IP or some other unique data. You'll have to store the IP or other data and remember it. When the user tries to up/down vote again, you'll have to check against that to see if you should let them do so. You should let them do the opposite though, in case they want to change their vote. You can do this with PHP and MySQL (and lots of other things).

Tom Dignan
Use IP to identify a user?? for real?
Pablo Fernandez
On average, the IP might identify a user uniquely for about 15 min, if what I've read about botnet enumerations is any use.
piggles
You will be fine, just don't tell 4chan about your website.
Tom Dignan
By the way, if you *don't* use IP, how are you going to tell if someone is using multiple accounts to pad upvotes?Try using multiple accounts on reddit, it gets your post hidden.Of course, you can have a big proxy list. Lets be honest though, there is only one group of hoodlums that does this.You just ban all known open proxies for starters.
Tom Dignan
How can anyone upvote this?
Pablo Fernandez
+6  A: 

Just store user id in the voting table.
So, you can always check if particular user already voted.
article-id, user-id, vote time and vote value columns is enough

Col. Shrapnel
+3  A: 

Two methods:

  • Client Side: Set into cookie (article IDs for last 5 or 10 votes ) and do not allow to vote again. This is easily hackable but allows you to implement without any database changes!
  • Server side: track each and every vote up and vote down in a table like <{userID}, {vote UP/DOWN}, {articleID}>

StackOverflow uses database to store all this data. They also lock your vote after some period so you cannot undo your action.

Ankit Jain
+2  A: 

I think the best way to do that is to store all votes and user ids in database, and if it gets bigger you can remove old records from the database after one week/month/etc and restrict voting on items that are older than a week/month/etc, so no one will be able to vote twice on the same item.

negative