Thursday, June 19, 2008

PHP: Web Bug Script

Somebody wanted hits on their website... so they linked web bug[wikipedia] web bug tracker article to their web bug script[pineapple.vg].

The problem with their web bug script is it requires the php-gd2 extension, it results in 95 byte output, and uses php gd code allocating memory... deallocating memory when its not necessary. This script when scaled up 100,000x has too large a footprint. It can be optimized into 3 lines as follows (with a 43 byte output):

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

header("content-type: image/gif");

//43byte 1x1 transparent pixel gif
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
?>

1 comment:

Anonymous said...

Joshua