vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Straight php include for web traffic stats (https://vborg.vbsupport.ru/showthread.php?t=161756)

jbd 11-02-2007 02:20 PM

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?

jbd 11-02-2007 02:46 PM

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?

jbd 11-02-2007 03:14 PM

Sure here a general rundown of the tracking script:

PHP Code:

<?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:
PHP Code:

<?
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.

jbd 11-05-2007 12:27 PM

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

Code:

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.

jbd 11-06-2007 10:42 AM

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


All times are GMT. The time now is 03:08 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02225 seconds
  • Memory Usage 1,753KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete