开发者

Counter increment on image load on server

I want counter hit increment i.e. to be save in database, Whenever a perticular image will preview on site/server.

For Eg: http://test.com/1234(ad_no)/1.jpg whenever this url going to load on site hit counter code should increase.But not in brower, like following code in html view not html source.

<div align="center"><center><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="75%;"><tbody><tr><td width="100%;"><a href="http://www.test.com/27123"> <img border="1" src="http://www.test.com/27123/1.jpg" width="720" height="541" />开发者_运维知识库</a></td></tr></tbody></table></center></div>


Instead of using <img src="image.png" alt="Image"/> use this:

<img src="load_image.php" alt="Image"/>

Now at load_image.php use the following code:

<?php 
    //Connect mysql server
    ....

    //Update your count
    ....

    //Return the image
    $image = file_get_contents('location/myimage.png'); 
    header('content-type: image/png'); 
    echo $image;
?>

It will first execute the php and then simply return the image file required. So this way you can keep a track of how many times that image was requested. This is the way most tracking pixels work.


you want to log showing of your image from another server?

You could do it with

  • Access log proccessing
  • Disallow direct access to jpg file and allow it for example on ad.php?image=/yourimage/url.jpg and then save it directly
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜