I was looking forward to add a feature to my project which can tell us how many times the post has been viewed, but just can't get how is it done. I am not a programming expert but still have good knowledge of php, mysql so if anybody can just give me idea how it is done. Currently I display all posts on main page and on clicking title of post user gets redirected to post page were full post is displayed so surely something is to be done on post page but what I have to count their?

The way you want it (without counting only special views e.g. from members) is quite easy. Add a “viewed” int counter with default 0 , in your table and each time the app displays the full post update it incrementing it by one e.g. (SET viewed = viewed + 1)

Edited 1 Year Ago by jkon

There is a problem with @jkon way. If a user keeps refreshing the page, the count will go up per fresh. As a result, the count number will be inflated. However, the part to save the counter in database is correct (SET viewed = viewed+1).

There is no way to get an accurate counting number of viewing but may get an approximate. However, there are various ways to prevent duplicated count from refreshing the same page (could be short or long term)...

Taywin the question was just , from where to start. There are methods that you can ensure most reliable as possible , that the article was actually read , e.g. An AJAX call when the user scroll the page to a certain point and a check server side against session id but also IP over a certain period of time. There are other methods also , better but more complex , there is no point to talk about those while we don't know yet if Harman_2 understood even the simplest one.

This article has been dead for over six months. Start a new discussion instead.