Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting how many times a image is being served from server?

Tags:

php

I want to count the no. of times a image is being served from our server. I have some images in a website and want to count the no. when these images are showed on web pages(served from the server to my website and if hotlinked). Is there any way to accomplish this. I know php so if there is some way doing it in php it would be really helpful.

advice please

thank you.

like image 715
RishiPatel Avatar asked Jan 18 '26 06:01

RishiPatel


2 Answers

Can't you look at your server logs for that?

like image 61
sprugman Avatar answered Jan 20 '26 21:01

sprugman


If you're wanting something beyond parsing server-logs, you'd have to setup a database to manage the list of images, and the number of times they're accessed. Serve the images through a .php script which increments the db value with each request. You could use a flat-file system too, but I prefer the db-solution.

You wouldn't need to worry about the source of your image if you implement .htaccess and apache's mod_rewrite. You could serve url's like this:

http://mysite.com/images/001.jpg

Which would be understood on the server as:

http://mysite.com/images.php?id=001

Thus providing a basis to perform database-actions, and scripted logic.

like image 44
Sampson Avatar answered Jan 20 '26 21:01

Sampson