Reputation: 1023
Let's start by the scenario:
The application has a Products section with +100 products and a "Visits Count" field is needed on every product's details page which shows number of visits for this product.
You need to prevent this Visit Count to +1 every time a certain visitor do a refresh on the page,
but you would like to allow that user's visit to be counted on next day visit.
So if you choose cookie approach you need 1 cookie per each product for a single visitor. Because with using a single cookie with sub-keys, you cannot tel which sub-key (product) should be expired as the whole cookie will expire on the given time.
Also as there are too many products, it's nearly nonsense (and not allowed) to have +100 cookies (or a single cookie with 100 sub-keys) for a curious visitor who wants to browse all products.
What's your suggestions?
Upvotes: 1
Views: 1166
Reputation: 18064
Why not use a database? You can create a table to store a list of this kind:
Then in each visit, you can check if the current user has visited the current product today. If so, do nothing. If not, add one record.
Then you can have a periodic task that processes this list each 10 minutes and updates the views field accordingly.
Upvotes: 0
Reputation: 522
I think the the two possible solutions is either by set cookies or record IP address , which the last one will change from time to time, so you have only the first option to use , and about the cookie time u can set it for a long period of time that makes it hard to expire.
Upvotes: 0
Reputation: 65431
You only need one cookie, to uniquely identify the user.
You can then in the pageload of the product page log which user looked at which product.
You then have a list of all visits, from this list you can select the unique daily visits of each user.
Upvotes: 1