View Full Version : Straight php include for web traffic stats
Hi there,
I am developing an in house web traffic stats package for use accross our network. This works by including a php file in the header template for each of our sites t0 logs relevant info.
We have a few instalations of vbulletin and would like to have some accurate stats for those areas, however I am having problems finding where best to include the tracking script.
Currently we have a custon header file defined in a plugin and this is loaded into the default template. The custom header file contains the tracking include directive.
The problem here is that accurate stats are not recorded, so in one day we have 3k+ page loads but all from the same IP (i.e. our server) with no referer or user agent information etc.
Can anyone advise of the best place to include the tracking script in order to get accurate results?
We are using Version 3.6.7
Andrew Green
11-02-2007, 02:23 PM
Check IP address and ignore anything from your own server?
Hi thanks for the reply but perhaps I havent made this clear.
The point is that no other IPs (or other info) are logged when the tracking file is included within VB. VB appears to make the call to the script rather than the end user.
I need to have this script run before VB takes over. The script logs information for all other pages without issue, it's only the header called by VB that contains almost no tracking data.
Andrew Green
11-02-2007, 02:48 PM
can you post your code? Are you using a external .php file, if so how are you calling it?
Sure here a general rundown of the tracking script:
<?PHP
//Track.php
//Track and log page load
require_once('includes/traffic.conf');
require_once('includes/TrafficDatabase.class.php');
require_once('includes/rc_SEReferer.class.php');
require_once('includes/Libfunctions.class.php');
function getUserIp()
{
$ipParts = explode(".", $_SERVER['REMOTE_ADDR']);
if ($ipParts[0] == "165" && $ipParts[1] == "21")
{
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR"))
{
$ip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("REMOTE_ADDR"))
{
$ip = getenv("REMOTE_ADDR");
}
} else
{
return $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function getReferer()
{
global $LibFunctions;
$strReferer = getenv('HTTP_REFERER');
if (!$strReferer)
{
return "Direct Request";
}
return $LibFunctions->clean_var($strReferer);
}
function getServerName()
{
global $LibFunctions;
$strServerName = $_SERVER['SERVER_NAME'];
return $LibFunctions->clean_var($strServerName);
}
function getQueryString()
{
global $LibFunctions;
$strQueryString = $_SERVER['QUERY_STRING'];
return $LibFunctions->clean_var($strQueryString);
}
function getUserAgent()
{
global $LibFunctions;
$strUserAgent = getenv('HTTP_USER_AGENT');
return $LibFunctions->clean_var($strUserAgent);
}
function getRemoteHost()
{
global $LibFunctions;
$strRemoteHost = $_SERVER['REMOTE_HOST'];
return $LibFunctions->clean_var($strRemoteHost);
}
$TrafficDataBase = new TrafficDatabase();
$LibFunctions = new LibFunctions();
if($TrafficDataBase)
{
$strSearchEngine = '';
$strSearchString = '';
$SEReferer = new rc_SEReferer(getReferer() . "?" .getQueryString());
if($SEReferer->isSearchEngine())
{
$strSearchEngine = $SEReferer->getSearchEngine();
$strSearchString = $SEReferer->getSearchQuery();
}
$TrafficDataBase->logHit(getServerName(), getUserIp(), $_SERVER['PHP_SELF'], getReferer(), getQueryString(), getUserAgent(), getRemoteHost(), $strSearchEngine, $strSearchString);
}
?>
The call is simply:
<?
include_once('/full/path/to/script/Track.php');
?>
This include directive has been added to all of our generic header files,and is incorporated into the default template of vbulletin.
Rather than return valid data we get our own server IP back and the name of the header file rather than the end user IP and the name of the forum page.
Any ideas?
Are there some core scripts that are called by every forum page that I can insert the additional include directive into?
class101
11-06-2007, 10:27 AM
yes answered you in the vb.com here 's how to do:
no you must add in your .htaccess this
php_value auto_prepend_file /path/to/your/codetoinclude.php
or
php_flag auto_prepend_file /path/to/your/codetoinclude.php
auto_append_file works so.
Or define it in the php.ini directly, this allow to include a php code to ALL server's requests but many shared hosting doesnt allow this. Im trying to find an alternative to this in a thread below if anyone can help me out.
Ah many thanks for your reply.
You may find it useful to know that I just overcame the problem by adding the include directive at the top of the "global.php" vbulletin file. I am now getting valid data for all pages accessed.
class101
11-06-2007, 10:47 AM
ok thanks for the tip, mine is working so for request like 404 wich are not indexed with vbulletin, but for your thing yeah global.php should be enough thanks
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.