I am developing an eCommerce website which contains around 2000-3000 products(no.can be increase in near future).So i need to count total page views for a particular product.
i know it can be simply done by just updating a mysql table on each page load but it’s not the right way to do this because some one just press the reload button again again and the page views goes up.
So i want to do it in a better way so total views no. somewhat closer to the unique/real one.
i just came up with an idea that i can do it in 3 ways:\
1.Using cookies so if i just store cookie for each product then check against it for next unique visit then it can be done but i think it’s not the better way to do this because if no of total cookies grows up then it will effect my page performance on each page request.
2.Using session i can use session to store data about each product and the visitor identity so i can track that is it a unique visit or a repeating one.But i think session data size also increase if a user visit more & more products with same session.
So is it good to use session for this purpose?
3.Use databse i can make a table page_views then update the count data by checking a time delay between the last visit and by matching the IP address and session id.
so please suggest me that which method is better to use and the best way to implement that method.
I am using PHP(Codeigniter 2.0.1)+Mysql
I would suggest you to create a new table to store session ID variable, along with an expire time of let’s say 2 hours. You can create a cookie with this ID on the client server, so that you don’t have to use MySQL queries repeatedly.
In my intranet, I have only created a
last_visitor_ipcolumn in my web-hits table, and I am storing the last IP there, so that continuous refreshes are not counted. 🙂