So, i want to do some metrics about the times one image is open, i need to give my users the link of the image but i need to track how many times they open it.
If i give them the link like http://webserver.com/image.png
i cant track how many times the images is opened, so i think if i can make a PHP script who streams the binary data when the user calls the link like http://webserver.com/image.php
, it maybe works.
In this scenario开发者_如何学C, i can simple write a metric script to store information like ip and time, but i don't know how to echo the image in order to show it on the browser. I think that maybe if i open the image in binary mode from the PHP script and then stream that information to the user it will work, but in this area i know nothing.
Some people can say that i can simple do an echo("image.png");
at the end of the script but this won't work if you think a little more.
Generally, you will want to tell the browser what type of content to expect, and then send the bytes of the content. For example:
incrementHitCounter();
logIP();
// Dear browser, a PNG file is coming your way
header("Content-Type: image/png");
// here it is
readfile("/path/to/image.png");
- http://php.net/manual/en/function.header.php
- http://php.net/manual/en/function.readfile.php
精彩评论