Increase view count

Hi all,

I’m building a website where you see a list of links (like hackernews). There are no single-link pages (like an article page) just a homepage with all the links.

Every link shows a view-count. When someone clicks on one of the links the view-count increases. Everything works perfect but I want to add something and I’m not sure where to start.

I want to increase the view-count only if you haven’t clicked the link already. Do I need to save the IP address after the you clicked on the link? And if so, how do I query all the IP address onload and immediately check if the current IP hasn’t clicked the link already?

I hope someone can help me out with this :slight_smile:

— Giel

Whatever you do, you will have a hard time to really prevent users from clicking the link more than once if they choose to do so, no matter if you check IP addresses or use cookies or local storage.

Dynamic IP addresses usually change if someone restarts their router; cookies can be deleted.

Having said that, you can of course make it harder by using any of the methods mentioned above, or even a combination of all.

As regards storing the IP addresses, you can of course store them in the content file for individual pages, or you could use a database. If someone then clicks the link, your script would check if the IP address has already clicked the link, and only increase the page counter if not.

Thanks for the reply, this helped a lot.

On each click I check if the ip is in the database. If not I save the ip in the database and redirect to the website. If it’s in the database I redirect directly. I know it doesn’t prevent the user from clicking the link more than once but it’s good enough for now.

Again, thanks for your help :slight_smile: