Search code examples
phprestrictionvote

how to restrict user not to vote an article more than once?


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 ?


Solution

  • 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.