Advertisement
Guest User

balexandre

a guest
Jan 7th, 2010
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. <?php
  2.     /*
  3.     *  Subject: Track Banner Clicks on Magento
  4.     *  Post Origin: http://www.magentocommerce.com/wiki/how_to/how_to_add_jw_image_gallery_xml-flash
  5.     *
  6.     *  Creator: Bruno Alexandre
  7.     *  Creation date: 08 January 2010
  8.     */
  9.  
  10.     date_default_timezone_set('UTC');
  11.  
  12.     // ######################################################################  Get Database Settings
  13.     $dbprefix = "";
  14.     $xml    = simplexml_load_file('../app/etc/local.xml');
  15.     $dbhost = $xml->global->resources->default_setup->connection->host;
  16.     $dbuser = $xml->global->resources->default_setup->connection->username;
  17.     $dbpw   = $xml->global->resources->default_setup->connection->password;
  18.     $dbname = $xml->global->resources->default_setup->connection->dbname;
  19.     if ($xml->global->resources->db->table_prefix != "")
  20.         $dbprefix = $xml->global->resources->db->table_prefix . ".";
  21.  
  22.     // for debug proposes, so you know it is loading the right values
  23.     /**
  24.     echo "<br/>dbhost: ".$dbhost.
  25.          "<br/>dbuser: ".$dbuser.
  26.          "<br/>dbpw: ".$dbpw.
  27.          "<br/>dbname: ".$dbname.
  28.          "<br/>dbprefix: ".$dbprefix."<br/>";
  29.     die();
  30.     **/
  31.        
  32.     // ######################################################################  Get Banner Information
  33.     $referer  = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';    // from witch page got here
  34.     $qstring  = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';    // what is the full query string info
  35.     $addid    = isset($_GET['adid']) ? $_GET['adid'] : '';              // advertisement ID
  36.     $landing  = isset($_GET['page']) ? $_GET['page'] : '';              // landing page (if none, will redirect to last line)
  37.     $date     = date(DATE_RFC822);                          // current date
  38.     $clientIp = getenv("REMOTE_ADDR");                      // client IP
  39.  
  40.     // ######################################################################  Create Insert Statement
  41.     mysql_connect($dbhost,$dbuser,$dbpw);  
  42.     @mysql_select_db($dbname) or die("Unable to select database");
  43.        
  44.     $query = "INSERT INTO " . $dbprefix . "ads_tracking " .
  45.              "(ad_datetime, ad_referer, ad_click, ad_clientip, ad_querystring) " .
  46.              "VALUES " .
  47.              "(NOW(), '$referer', '1', '$clientIp', '$addid');";
  48.    
  49.     // ######################################################################  Execute Insert Statement
  50.     $result = mysql_query($query);
  51.     if (!$result) {
  52.         //die('Invalid query: ' . mysql_error());
  53.     }
  54.     mysql_close(); 
  55.  
  56.     // ######################################################################  Redirect User to Landing Page
  57.     if(strlen($landing) > 0)
  58.         header("Location: $landing");
  59.     else
  60.         header("Location: http://www.mydomain.com/");               // TODO: Add your Store URL here
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement