home   articles   tags   browse code   

PHP Web Bug - Transparent gif Tracking


 

A Web bug, or tracking beacon is usually a 1x1 transparent gif (the smallest possible image), which is embedded into webpages or emails that support images. When the webpage is viewed, the browser sends an http request to fetch the image. The request is mapped to a script which is executed and can store user information like ip address and access time on the server. The web server requested an image and not a script after all, so the last line of the script usually outputs a 1x1 transparent image so the user will never notice it.

Many webmail programs like gmail will not automatically display images embedded into email to prevent web bug email tracking in email and spam.

Wikipedia featured an external link in its web bug article to some bad php. Why is it bad? It is not portable (it requires the gd2 php extension), nor is it efficient. It takes a lot of overhead to load the extension and allocate an image. For scalability reasons, it is better to hard code the 1x1 transparent image so the image is not needlessly generated on the fly.

<?php
//saves ip address and timestamp
$str=date("Y-m-d H:i:s") . ": ". $_SERVER['REMOTE_ADDR'] . "\n";
file_put_contents("ip_list.txt", $str, FILE_APPEND);

header("content-type: image/gif");
//43byte 1x1 transparent pixel gif
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
?>
 

Tags: php
 
andy on Mar 18th, 2009 7:28 pm said:
this doesn't work. in firefox you get the messed up image symbol.
 

eugene on Jul 9th, 2009 12:47 am said:
This works fine on FF3.5 could also try dataURI instead of base64. http://en.wikipedia.org/wiki/Data_URI_scheme but not compatible on older browsers like IE.
 



 

 



Related Articles
 


home  |  privacy policy  |  terms of use  |  contact  


©2012, Zedwood.com

zedwood.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com