Hi all,

Iv made a simple 5 star voting system and need a way to make sure the user can't vote on the same product again in the next hour.

I'm not a mathmatician and get really confused with the time calculations and have tried quite a few methods now and have not got anywere.

What would be the best way to do this? Cookie? Save their IP and timestamp in a database and work out if they are aloud to vote from that?

Thanks in advance,


The very easiest way would be to allow only registered users to vote (as it is done at youtube, amazon, and also here).

If you don't want the visitor to sign-up you can do it with a cookie, but you must be aware that not everybody is accepting cookies and many people regulary delete them.
You could also do it as you said with saving the IP-address in a database. But as soon as the user relogins to the internet it has a totally new IP. Some might even use programmes that changes their IP-address every few seconds.

When you decide for one of the two latest ideas you cannot guarantee that a user doesn't vote more than once an hour. But therefore you can leave out a registration which might be unattractive for many users. If users have to sign up anyway when buying a product, I'd go for the very first solution.


dont use the Ip. If they are behind NAT, one person could vote in a huge university or somewhere, meaning no one else could.

okay, thanks for the advice sDJH and jbennet, I think ill go for the cookie option and use the product ID number (primary key) as the cookie name and ise php's isset function.

Thanks again :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.