<?php
/*
* Subject: Track Banner Clicks on Magento
* Post Origin: http://www.magentocommerce.com/wiki/how_to/how_to_add_jw_image_gallery_xml-flash
*
* Creator: Bruno Alexandre
* Creation date: 08 January 2010
*/
date_default_timezone_set('UTC');
// ###################################################################### Get Database Settings
$dbprefix = "";
$xml = simplexml_load_file('../app/etc/local.xml');
$dbhost = $xml->global->resources->default_setup->connection->host;
$dbuser = $xml->global->resources->default_setup->connection->username;
$dbpw = $xml->global->resources->default_setup->connection->password;
$dbname = $xml->global->resources->default_setup->connection->dbname;
if ($xml->global->resources->db->table_prefix != "")
$dbprefix = $xml->global->resources->db->table_prefix . ".";
// for debug proposes, so you know it is loading the right values
/**
echo "<br/>dbhost: ".$dbhost.
"<br/>dbuser: ".$dbuser.
"<br/>dbpw: ".$dbpw.
"<br/>dbname: ".$dbname.
"<br/>dbprefix: ".$dbprefix."<br/>";
die();
**/
// ###################################################################### Get Banner Information
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // from witch page got here
$qstring = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; // what is the full query string info
$addid = isset($_GET['adid']) ? $_GET['adid'] : ''; // advertisement ID
$landing = isset($_GET['page']) ? $_GET['page'] : ''; // landing page (if none, will redirect to last line)
$date = date(DATE_RFC822); // current date
$clientIp = getenv("REMOTE_ADDR"); // client IP
// ###################################################################### Create Insert Statement
mysql_connect($dbhost,$dbuser,$dbpw);
@mysql_select_db($dbname) or die("Unable to select database");
$query = "INSERT INTO " . $dbprefix . "ads_tracking " .
"(ad_datetime, ad_referer, ad_click, ad_clientip, ad_querystring) " .
"VALUES " .
"(NOW(), '$referer', '1', '$clientIp', '$addid');";
// ###################################################################### Execute Insert Statement
$result = mysql_query($query);
if (!$result) {
//die('Invalid query: ' . mysql_error());
}
mysql_close();
// ###################################################################### Redirect User to Landing Page
if(strlen($landing) > 0)
header("Location: $landing");
else
header("Location: http://www.mydomain.com/"); // TODO: Add your Store URL here
?>