简体   繁体   中英

How can I know whch web site loads my image?

I have created some free HTML Templates, to share them for free, but I would like to know where my templates are installed.

What I have in my mind, in order to track the template installation, is to create a php script that will generate a single pixel image. I would like to use that image to collect information about the web site that loads my picture.

So, how can I know which server is requesting my image? Any ideas?

Try using $_SERVER['HTTP_HOST'] . Or if you need something else, try here : http://www.php.net/manual/en/reserved.variables.server.php

When you generate your single pixel image, include information that you're interested in such as this. Then check your server logs.

echo '<img src="onepixel.png?servedby='.$_SERVER['HTTP_HOST'].">';

Obviously whatever you do could be stripped out, since once your template code is obtained the user could just delete the reference to track back to your script.

A pixel loading off of your server would work, you could access the data within $_SERVER to find out some information about the request and look for a referrer.

A better idea, IMO, is to write some javascript code that lives on your server and is included via a <script src="..."></script> tag on your template. This would allow you to "phone home" by dynamically creating an image source tag to fire this pixel off to your server with more information about the source.

For example, you could so something as simple as this:

(function()
{
    var img = document.createElement('img'),
    src = "//www.yourserver.com/path/to/pixel.php?domain=" + document.domain;

    img.src = src;
})();

This would fire a pixel to your server and contain the domain that loaded your template. You could add a bunch more code that identifies the browser, uniquely tracks the user - see what kind of traffic the site is getting, whatever.

Be sure you don't use any 3rd party JS libraries, as you don't want to inject dependencies/increase load time on the site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM