Bogotobogo
contact@bogotobogo.com
- PHP Home
- Apache, PHP, and MySQL Installation
- PHP Preview
- PHP Preview II
- Reserved Words
- Variables
- Functions
- Arrays
- Arrays II
- Creating Dynamic Content - Date and Time
- Creating Dynamic Content II - Form Values
- Creating Dynamic Content III - PHP_SELF
- File Handling - Delete and Copy
- File Handling II - Reading and Writing
- File Handling III - Uploading Files
- cURL
- Cookies and Sessions I - Setting and Getting Cookies
- Cookies and Sessions II - Access Limit and Starting a Session
- Cookies and Sessions III - Cookie vs Session
- Creating MySQL Database and Table
- Creating MySQL Database and Table II - Table and Query
- Creating MySQL Database and Table III - Retrieving and Sorting Data
- Creating MySQL Database and Table IV - mysqldump etc.
- MySQL with PHP: Part I - User and Password
- MySQL with PHP: Part II - Creating and Deleting Database
- MySQL with PHP: Part III - Creating Database Table Dynamically
- Ad Tracker
- phpbb and Adsense
The code below, puts a trackering pixel after converting a 1x1 png to transparent 1x1 png image. Then, it gather infomation of the device (browser, iPhone, iPad, or Android etc), and save it to the log file.
<?php
// pixel.php
header("Content-type: image/png");
$image = imagecreatefrompng("images/tracker/tracker_pixel.png");
imagecolortransparent ( $image,imagecolorallocate($image, 255, 255, 255));
imagepng($image);
$info=$_SERVER['REMOTE_ADDR'].'","'
.$_SERVER['HTTP_USER_AGENT'].'","'
.$_SERVER['HTTP_REFERER'].'","'
.date("D dS M,Y h:i a").'"'."\n";
$file= 'tracker_log.csv';
$fp = fopen($file, "a");
fputs($fp, $info);
fclose($fp);
?>
Here is the tracker pixel:
tracker_pixel.png
tracker_pixel_transparent.png
If we hit the page, pixel.php, though we can't see anything on the page, we know it's there.
But we get log file, tracker_log.csv, something like this:
69.225.239.92","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2", "http://www.bogotobogo.com/php/tracker_pixel.php","Wed 14th Dec,2011 12:55 pm" 69.225.239.92","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB7.2; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; HPNTDF; BRI/1; InfoPath.2; .NET4.0C; .NET4.0E)", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 12:55 pm" 69.225.239.92","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 12:55 pm" 69.225.239.92","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2","", "Wed 14th Dec,2011 12:55 pm" 69.225.239.92","Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 12:58 pm" 69.225.239.92","Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_5 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8L1 Safari/6533.18.5", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 12:58 pm" 174.253.249.129","Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 Build/VZW) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 854X480 motorola DROID2", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 01:35 pm"
Pixel tracking is accomplished by constructing 1x1 pixel fetch commands that have additional query string parameters appended in the form of 'PARAMETER NAME' = 'PARAMETER VALUE' pairs that in turn send tracking code data to info analyzing place.
Actually, the tracker pixel is not implemented the same way as we did (pixel.php). So, let's modify the file as below after commenting out the pixel portion as use php just to get the info:
<?php
// pixel2.php
// header("Content-type: image/png");
// $image = imagecreatefrompng("images/tracker/tracker_pixel.png");
// imagecolortransparent ( $image,imagecolorallocate($image, 255, 255, 255));
// imagepng($image);
$info=$_SERVER['REMOTE_ADDR'].'","'
.$_SERVER['HTTP_USER_AGENT'].'","'
.$_SERVER['HTTP_REFERER'].'","'
.date("D dS M,Y h:i a").'"'."\n";
$file= 'tracker_log.csv';
$fp = fopen($file, "a");
fputs($fp, $info);
fclose($fp);
?>
If we put the pixel2.php just before the end of the </body> of our page, we get a report whenever the page is opened. For example, I put the code on this track.php file, I get the following log when I refresh this page with Chrome:
69.225.239.92","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2", "http://www.bogotobogo.com/php/tracker.php","Wed 14th Dec,2011 01:48 pm"
Let's put some link to the pixel like this:
<html> <body> <img src = "http://www.bogotobogo.com/php/do_tracking.php?" width="1" height="1"/> <?php ... ?> </body> </html>
The do_tracking.php which is linked to the pixel will do all the tracking trick for us. It could be php, javascript, or perl. The parameter pairs after ? send tracking code data to the script.
- PHP Home
- Apache, PHP, and MySQL Installation
- PHP Preview
- PHP Preview II
- Reserved Words
- Variables
- Functions
- Arrays
- Arrays II
- Creating Dynamic Content - Date and Time
- Creating Dynamic Content II - Form Values
- Creating Dynamic Content III - PHP_SELF
- File Handling - Delete and Copy
- File Handling II - Reading and Writing
- File Handling III - Uploading Files
- cURL
- Cookies and Sessions I - Setting and Getting Cookies
- Cookies and Sessions II - Access Limit and Starting a Session
- Cookies and Sessions III - Cookie vs Session
- Creating MySQL Database and Table
- Creating MySQL Database and Table II - Table and Query
- Creating MySQL Database and Table III - Retrieving and Sorting Data
- Creating MySQL Database and Table IV - mysqldump etc.
- MySQL with PHP: Part I - User and Password
- MySQL with PHP: Part II - Creating and Deleting Database
- MySQL with PHP: Part III - Creating Database Table Dynamically
- Ad Tracker
- phpbb and Adsense