Forum Moderators: coopster
My question is, what would be the best way to limit the number of unique image views? In a previous script I made I made use of sessions, and built an array containing the image ids of the images they have viewed. I logged in a database how many views the IP had made.
However as you can imagine using the IP method isnt always best.
So I come to you :) What are some alternatives you can suggest which would be effective but most importantly FAST.
Thank you in advance.
What about SwfObjects? As I recall these are sort of flash cookies, do they get deleted as well? I'm not sure.
Would be worth to investigate.
Perhaps the mysql method is the best way to do for that however can some suggest a proper database structure and efficient queries I could use to prevent overloading the server at high traffic times.
My question is, what would be the best way to limit the number of unique image views?
Since you're in the PHP forum, my guess is this is how you would prefer to do it.
- Write a little script that outputs images. Using PHP open methods. Assume the image and user is registered in the database, and the image id is 123.
on request of "img_id=123"
- check views for user for img id 123, if exceeded, send to log in.
- otherwise open file with PHP
- print appropriate content-type header (image/gif/image/jpg, etc.)
- while reading in file, print to browser
- close file (don't forget to do this, flushes buffer)
- increment user's view in the database.
Change all your image src's to
<img src="your_image_script.php?img_id=123">
Done. Well, almost. Note that this doesn't manage unique views and will increment refreshes, so you'd need session variables or cookies to make sure it's a unique request. Should be elementary from there, though.