Jump to content

Counting Image Views


Warptweet

Recommended Posts

I use this code to count how many times an image is viewed on the viewing page on my website:

 

$con = mysql_connect("?????","???????","????");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("???????", $con);

mysql_query("UPDATE files SET views = views+1 WHERE file_id = '$id'");

 

So that works of course. Although, there is a problem. When somebody uploads a file on my website, they are also given a direct link to the image/picture. If they post that image/picture somewhere else on the internet, the above code is obviously not executed, meaning the view count is innacurate.

 

How can I count how many times the image has been viewed including outside of my websites page? Is it possible to count how many times the image files has been requested from my server?

Link to comment
https://forums.phpfreaks.com/topic/52591-counting-image-views/
Share on other sites

Yes, I have access to my webserver logs, I can access pretty much everything.

Would you mind showing me how, or giving me your script if it's already made?

 

I'd prefer being shown how or somewhat getting an explanation on how you would do it. I'd rather have my MySQL Database contain how many times it has been viewed, rather than acessing the webserver logs every time... Although, whichever way is easier for you is fine with me.

 

Thanks,

-Warptweet

Link to comment
https://forums.phpfreaks.com/topic/52591-counting-image-views/#findComment-259572
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.