Basically, I have a blog where I want to add a rating system, which will allow users to rate each post on a scale from 1 to 5. I do not want the users to sign in, as that is too much hassle from my part. However, I also want to save some of the ratings.

For instance, lets say X is a user who rated an article 3/5. When X visits this article again, I want to be able to identify X and tell him/her that he/she has already rated this article 3/5. So of course, some data needs to be saved in my database. Whats the best way to do this? I can collect X's cookie or IP and keep it in my DB, and each time this cookie/IP rates an article, I simply save it under the cookie/IP.

For my case, what will be better to use : cookies or IP? And if possible, can anyone explain the differences between the 2? Are cookies simply unique strings that identify a device uniquely? Do cookies change for a device and if so, at what frequency? Thanks.

  • 2
    Is showing that people have already rated the post a convenience function, or do you want to actively prevent that someone rates the same post twice? Commented Jun 2, 2016 at 13:49
  • Each person will be able to rate an article once. Thats what I want essentially.
    – darkhorse
    Commented Jun 2, 2016 at 13:55
  • 5
    You can't guarantee that a person only rates it once, PERIOD. Even with a login, because they can just make more logins if they want. You can't even get close with cookies or IP tracking, because users can clear their cookies, and will have different IPs for different devices, networks, etc. You say its a blog that you wish to add a rating system to. Do you see many such features out in the real blogsphere? Nope, because its really hard/impossible/totally not worth it anyway. People constantly try to game online polls for major elections/issues and such. I suggest you don't even bother trying.
    – GHP
    Commented Jun 2, 2016 at 14:12

1 Answer 1


A Cookie is a string of data which is stored on the user's browser and is associated with the domain that created it. All subsequent requests that the browser makes to your domain will include the contents of that cookie. It can also be read/write via Javascript on the page. It's essentially a piece of data on the browser that is "owned" by your domain.

The IP address is the unique identifier used to send/receive requests over the internet. A group of computers sharing the same network may have the same IP address.

If your main goal is to prevent multiple votes by a single user, then IP address would be more suitable, as it is generally harder to change IP address then it is to clear your cookies. Another weakness of cookies is, when browsing in incognito mode, the cookies are destroyed when the session ends.

A benefit to cookies over IP address is, you can store the rating completely on the client side, without having to store anything in your database.

  • 1
    I would advise against IP address myself. What happens for users behind a proxy or NAT? In that case, only one of them may vote, potentially excluding many users in the same network. Commented Jun 2, 2016 at 20:38
  • Why would one want to save the rating/vote of a poll at the client side? What would be shown as the result?
    – beppe9000
    Commented Mar 27, 2017 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.