Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 11-02-2007, 02:20 PM
jbd jbd is offline
 
Join Date: Jul 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 11-02-2007, 02:23 PM
Andrew Green's Avatar
Andrew Green Andrew Green is offline
 
Join Date: Nov 2005
Location: Winnipeg, MB
Posts: 996
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check IP address and ignore anything from your own server?
Reply With Quote
  #3  
Old 11-02-2007, 02:46 PM
jbd jbd is offline
 
Join Date: Jul 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 11-02-2007, 02:48 PM
Andrew Green's Avatar
Andrew Green Andrew Green is offline
 
Join Date: Nov 2005
Location: Winnipeg, MB
Posts: 996
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

can you post your code? Are you using a external .php file, if so how are you calling it?
Reply With Quote
  #5  
Old 11-02-2007, 03:14 PM
jbd jbd is offline
 
Join Date: Jul 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 11-05-2007, 12:27 PM
jbd jbd is offline
 
Join Date: Jul 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Any ideas?

Are there some core scripts that are called by every forum page that I can insert the additional include directive into?
Reply With Quote
  #7  
Old 11-06-2007, 10:27 AM
class101 class101 is offline
 
Join Date: Sep 2007
Location: France
Posts: 134
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 11-06-2007, 10:42 AM
jbd jbd is offline
 
Join Date: Jul 2004
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 11-06-2007, 10:47 AM
class101 class101 is offline
 
Join Date: Sep 2007
Location: France
Posts: 134
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:54 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04881 seconds
  • Memory Usage 2,259KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete