Q:

Anonymous User Counter for Viewing Images

I'm just starting with PHP. I'm currently building a site that will allow anonymous users to view images ten times a day. Any image viewed will increase the counter as well viewing a certain image more than once. Viewing more than the counter limit per day will not be allowed unless they register.
Just wondering what can I do with sessions and the database in order to make this possible. Also, how can I reset the counters in every 24 hours?
Sample codes would be much appreciated. Thanks.
BTW, I'm using kohana 3.

A:

If you use sessions, then there's an easy way for people to get around it - disable cookies.
You could base it on IP address, though you'd have to note that multiple people may sometimes have the same IP and one person may have multiple IPs.  So you would have to be conservative with what you reject - you wouldn't want to reject the same IP from access something just ten times in a day.
So, there's no ultra-reliable way of doing what you want to do, if you don't want to force people to register/login (and even then you'd have to account for people registering multiple times).
I'd probably consider limiting it by IP, putting a row into the database for each view containing the date and the user's IP, and if the row exists, increment a third column.  Once that column reaches say 100, disallow access.  The next day, it'll all be reset by itself because your date column is now different.
You may also consider putting a rule into robots.txt to prevent reputable search engines and the like grabbing 'cached' copies of the image.

