Updating number of topic views

Greetings all,

Just want to hear other people’s point of view. So, I have built this pretty much simple forums page for my website and one of the scripts (viewforum.php), when clicked, displays a table with different topics (threads). And one of the columns of this chart is called “Views”, which stands for “number of times each column has been viewed”. So, what I did is: when a person clicks’s on the topic’s (thread’s) title, a person is taken to view that thread and an DML SQL statement updates the column value for that specific topics which was clicked. The SQL is:

UPDATE topics
SET visits = visits + 1
WHERE id = '$topic_id'

Please note, the default of “visits” column is 0.
What I am worried about is a possible value manipulation. There is really no benefit or harm if someone simply keeps on refreshing a page and the value of “visits” will be incremented. But it still kind of feels wrong and I believe I am doing something wrong.
Please advise, what would be a correct or better way to implement the feature.


Even here at sitepoint I can see that they don’t simply update the value for “visits” if a person visits the same page twice in a short period of time. So, they somehow are able to tell if I am the same user. How is that done?

My guess is they have another table (f.e. views) where they store the IP and the page viewed.

Thanks for the tip guys, very much appreciated. Will give it a go and see if it works.

Thumbs up!

store the ip address in another table and check whether visitor’s ip address exists in the table or not.

If the visitor’s ip address in not in the table then update the visit count else not.