PHP Web Bug - Transparent gif TrackingA 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 | Related Articles php Calculate Script Duration in PHP and... Generate CSV Spreadsheet with PHP Generate PDFs with PHP Generate XLS Spreadsheet files with ... How to properly escape inline javasc... HTML Table Row Highlight PHP - Resize an Image with GD PHP Calculate Duration of MP3 PHP Create Zip file PHP mail Function With Attachments |