Page 1 of 1

Best place to include counter/statistics-script

Posted: Fri Jun 22, 2007 10:24 am
by Dawn
Hi,

I'm using a counter/statistics-script called "phptraffica" which needs to be included in a place of the script which is loaded at every page.

This 2 lines have to be included:
Code:
// Statistics
$sid="24360";
include("/var/www/vhosts/domain.com/httpdocs/phptraffica/write_logs.php");

The best place would be a place where which identifies the loaded page clearly that I can get the exact stats. But I don't know where... What would you suppose?

Greets,
Dawn

Re: Best place to include counter/statistics-script

Posted: Fri Jun 22, 2007 11:20 am
by garvinhicking
Hi!

You can create a file "config.inc.php" of your template and put the code in there. That file is interpreted whenever the frontend is displayed.

Regards,
Garvin

Posted: Tue Jun 26, 2007 10:02 am
by Dawn
Hi Garvin,

Thanks for your answer :) I've created the file config.inc.php in my selected template folder. I used the following code and gave it the ownership which I use for the other s9y files too:

Code: Select all

<?php
// Statistics 
$sid="24360"; 
include("/var/www/vhosts/domain.com/httpdocs/phptraffica/write_logs.php");
?>
When I try then to access my blog, it only displays the header of my blog and the text "no entries found". Do you have any idea how I can fix that?

Greets and best regards,
Dawn

Posted: Tue Jun 26, 2007 12:57 pm
by garvinhicking
Hi!

It could be that this 'write_logs.php' file messes with the variables or the request flow.

Does it work again properly after you remove the config.inc.php file again? If so, you will please need to ask the creators of the script for assistance.

Best regards,
Garvin

Posted: Tue Jun 26, 2007 3:02 pm
by Dawn
Hi Garvin,

Yes if definitly works again when I outcoment it. And yes it's something in "write_logs.php". I asked there for help but I don't know if they support their tool for including in such a complex environment like serendipity. Anyway, here would be the source:

Code: Select all

?php
/***************************************************************************
 phpTrafficA @soft.ZoneO.net
 Copyright (C) 2004-2007 ZoneO-soft, Butchu (email: "butchu" with the domain "zoneo.net")

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

global $server, $user, $password, $base, $config_table, $path;
global $ip2c;

$path =  __FILE__;
$path = preg_replace( "'\\\write_logs\.php'", "", $path);
$path = preg_replace( "'/write_logs\.php'", "", $path);

// echo $path;

include ("$path/Php/config_sql.php");
include ("$path/Php/config.php");
include ("$path/Php/sites.php");
include ("$path/Php/funct.country.inc.php");
include ("$path/Php/log_function.php");

// Fixing the path to the ip2c database
$ip2c = $path."/".$ip2c;

if (!isset($phpTrafficA) or $phpTrafficA=="") {
        if (isset($_COOKIE['phpTrafficA'])) $phpTrafficA = $_COOKIE['phpTrafficA'];
}

if (!array_key_exists ($sid, $sites)) {
        header('Location: index.php');
}
// Setting some variables that should have been set in config.php, but if
// the file is old, they might be missing
if (!isset($cookieTxt)) {
        $cookieTxt = "Admin";
}

//echo  "$phpTrafficA";
$DEBUG = 0;
if ($phpTrafficA != "Admin") {
        if ($sites[$sid]['trim']) {
                $To = $_SERVER["PHP_SELF"];
        } else {
                $To = $_SERVER["REQUEST_URI"];
        }
        $servertime = time();
        $table = $sites[$sid]['table'];
        $domain = $sites[$sid]['site'];
        if ($_SERVER["REMOTE_ADDR"] != "195.190.158.2") {
                $count = logit($table, $domain, $To, $_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"], $servertime, $_SERVER["HTTP_REFERER"], $sites[$sid]['crawler']);
                if ($sites[$sid]['counter']) echo $count;
        }
} else {
        echo $cookieTxt;
}
?>
As just a dirty hack I've included this two lines in include/functions.inc.php (of serendipity, at the very top) and there it works (strange)... Not very nice but it does.

Thanks anyway, but if you have an idea what could be the problem, pls let me know ;)

Greets and best regards,
Dawn

Posted: Tue Jun 26, 2007 3:15 pm
by garvinhicking
Hi!

Okay, that script is bad for s9y. They should encapsulate their variables in some other master variable. As it stands, it overrides vital s9y variables and thus you can't embed it into serendipity.

I know there are statistic tools that make propre use of functions/classes and variable scopes, maybe you can search for a different statistic tool?

Or ask their support to rewrite it for proper variable encapsulation.

Best regards,
Garvin

Posted: Wed Jun 27, 2007 8:21 am
by Dawn
Thanks for your time and detailed answer.

It's very ironic, I saw the autor of phptraffica just released yesterday a new version where it works now without any problems :)

Greets and big THX again,
Dawn

PS: But if you know a better statistics tool for detailed reports than phptraffica it would be nice if you can tell me the name.

I use for general stats awstats, but it isn't very detailed. So I use for the different sections on my webspace an additional tool, in my case phptraffica.