
balexandre
By: a guest on
Jan 7th, 2010 | syntax:
PHP | size: 2.58 KB | hits: 109 | expires: Never
<?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
*/
// ###################################################################### Get Database Settings
$dbprefix = "";
$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
$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
if (!$result) {
//die('Invalid query: ' . mysql_error());
}
// ###################################################################### Redirect User to Landing Page
else
header("Location: http://www.mydomain.com/"); // TODO: Add your Store URL here
?>