Sorry for what will become a long post... I have submitted version 1.5 of User Tracking... This version includes a rewrite of the data capture portion of UT. This is the portion that Blessisaacola has been describing as an issue. This does not address the other portion of data capture desired to be changed, but specifically the potential of information being supplied to UT that would cause errors to be captured. While I could possibly list individual changes made, the majority of the functional changes are in the catalog side of the program. First is the list of information submitted tonight for review (probably too late to be posted this weekend).
The below code partially addresses item one below; however, it is the most significant revision and should be implemented at one's earliest convenience. Items 2 and 3 can be found using links previously posted in this forum. Item 4 was simply to bring the code more into ZC standard.
Updated 12/08/2013 Version 1.5
- Corrected a long standing issue with capturing data from the URL. The URLs are still truncated; however, they are now sent through for cleansing using Zen Carts db class prior to being sent to the SQL. This should reduce the occurrences of/prevent the SQL statement failure.
- Incorporated a new GeoIP.dat file (recent as of: Dec-05-2013. Similar updates can be obtained from: http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz.
- Incorporated a new geoip.inc file to accompany the GeoIP.dat file. The geoip.inc file can be obtained from: https://raw.github.com/maxmind/geoip-api-php/master/src/geoip.inc.
- Incorporated zen_href_link to generate links.
UPDATING INSTRUCTIONS:
For SQL statements: If updating from version 1.4.2, then: Use the UPDATE_VER.sql after any other SQL statements (This will update the version number of User Tracking)
otherwise same instructions as applicable from the 11/10/2013 update.
Files Updated from Version 1.4.4:
includes/functions/extra_functions/user_tracking.php
YOUR_ADMIN/user_tracking.php
YOUR_ADMIN/user_tracking_config.php
YOUR_ADMIN/includes/GeoIP.dat
YOUR_ADMIN/includes/geoip.inc
YOUR_ADMIN/includes/functions/extra_functions/user_tracking.php
Added UPDATE_VER.sql
Below is the entire code of shop/includes/functions/extra_functions/user_tracking.php which should be used to replace the previous version of this function. Update of the other files is not considered quite as crucial. Do not copy this code as written to any other file, the admin version of this is different.
<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright (c) 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: usertracking 2004-12-1 [email protected] http://open-operations.com
function zen_update_user_tracking()
{
global $db;
global $customer_id, $languages_id, $_GET;
foreach(explode(",", CONFIG_USER_TRACKING_EXCLUDED) as $skip_ip) {
$skip_tracking[trim($skip_ip)] = 1;
}
if ($_SESSION['customer_id']) {
$wo_customer_id = $customer_id;
$customer = $db->Execute("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
$wo_full_name = $db->prepare_input($customer->fields['customers_firstname'] . ' ' . $customer->fields['customers_lastname']);
}
else {
$wo_customer_id = '';
$wo_full_name = $db->prepare_input('Guest');
}
$wo_session_id = $db->prepare_input(zen_session_id());
$wo_ip_address = getenv('REMOTE_ADDR');
$wo_last_page_url = addslashes(getenv('REQUEST_URI'));
$referer_url = ($_SERVER['HTTP_REFERER'] == '') ? $wo_last_page_url : $_SERVER['HTTP_REFERER'];
if (($_GET['products_id'] || $_GET['cPath'])) {
if ($_GET['cPath'] && ZEN_CONFIG_SHOW_USER_TRACKING_CATEGORY == 'true') { // JTD:12/04/06 - Woody feature request
$cPath = $_GET['cPath'];
$cPath_array = zen_parse_category_path($cPath);
$cPath = implode('_', $cPath_array);
$current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
$page_desc_values = $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $current_category_id . "'");
$page_desc = $db->prepare_input($page_desc_values->fields['categories_name'] . ' - ');
}
if ($_GET['products_id']) {
$page_desc_values = $db->Execute("select products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = '" . $_GET['products_id'] . "' and language_id = '" . $_SESSION['languages_id'] . "'");
$page_desc .= $db->prepare_input($page_desc_values->fields['products_name']);
}
}
else {
$page_desc = $db->prepare_input(HEADING_TITLE);
if ($page_desc == "HEADING_TITLE")
$page_desc = $db->prepare_input(NAVBAR_TITLE);
}
$current_time = $db->prepare_input(time());
$current_time = $current_time;
if ($skip_tracking[$wo_ip_address] != 1) {
// JTD:05/15/06 - Query bug fixes for mySQL 5.x
$wo_ip_address = $db->prepare_input($wo_ip_address);
$cust_id = $_SESSION['customer_id'];
if ($cust_id == NULL) {
$cust_id = 0;
}
$cust_id = $db->prepare_input($cust_id);
$customers_host_address = $_SESSION['customers_host_address']; // JTD:11/27/06 - added host address support
$customers_host_address = $db->prepare_input($customers_host_address);
$page_desc = substr($page_desc, 0, 63);
/* Start - User tracking v1.4.3b modification*/
/*while (strpos(substr($page_desc, -1), '\\') !== false) {
$page_desc = substr($page_desc, 0, -1);
}*/
/* End - User tracking v1.4.3b modification*/
$wo_last_page_url = $db->prepare_input($wo_last_page_url);
$wo_last_page_url = substr($wo_last_page_url, 0, 125);
/* Start - User tracking v1.4.3b modification*/
/*while (strpos(substr($wo_last_page_url, -1), '\\') !== false) {
$wo_last_page_url = substr($wo_last_page_url, 0, -1);
}*/
$referer_url = $db->prepare_input($referer_url);
$referer_url = substr($referer_url, 0, 253);
/*while (strpos(substr($referer_url, -1), '\\') !== false) {
$referer_url = substr($referer_url, 0, -1);
}*/
$user_track_array = array();
$user_track_array[] = array('fieldName'=>'customer_id', 'value'=>$cust_id, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'full_name', 'value'=>$wo_full_name, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'session_id', 'value'=>$wo_session_id, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'ip_address', 'value'=>$wo_ip_address, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'time_entry', 'value'=>$current_time, 'type'=>'date');
$user_track_array[] = array('fieldName'=>'time_last_click', 'value'=>$current_time, 'type'=>'date');
$user_track_array[] = array('fieldName'=>'last_page_url', 'value'=>$wo_last_page_url, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'referer_url', 'value'=>$referer_url, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'page_desc', 'value'=>$page_desc, 'type'=>'string');
$user_track_array[] = array('fieldName'=>'customers_host_address', 'value'=>$customers_host_address, 'type'=>'string');
/* End - User tracking v1.4.3b modification*/
$db->perform(TABLE_USER_TRACKING, $user_track_array);
// $db->Execute("insert into " . TABLE_USER_TRACKING . " (customer_id, full_name, session_id, ip_address, time_entry, time_last_click, last_page_url, referer_url, page_desc, customers_host_address) values ('" . $cust_id . "', '" . $wo_full_name . "', '" . $wo_session_id . "', '" . $wo_ip_address . "', '" . $current_time . "', '" . $current_time . "', '" . $wo_last_page_url . "', '" . $referer_url . "', '" . $page_desc . "', '" . $customers_host_address . "')");
}
}
?>