I guess you're right. The elaborated post is a byproduct of my frustration of trying to fix this thing myself.

The name of the script I am trying to implement is "Audistat" v 1.13. It can be found at
http://adubus.free.fr/audistat/. It is a very simple counter script with a few additional statistical info that simple requires a mySQL backend and the one "required" line:
require($REDIRECT_HOMEDIR . "stats/stats.php");
I chose to put it in the theme.php under my water_drop theme. That way, it is contained in every page coppermine generates. I also tried including it in only the index.php, even before all the coppermine code is loaded, but still no go!
Here is the contents of stats.php (which if called upon directly in the browser, successfully executes and enters records flawlessly into the mySQL database):
<?php
//
// AudiStat v1.2 by Alexandre Dubus
// April 2003
//
// Add to the beginning of all your PHP pages (in a PHP block code) :
// require("stats/stats.php");
//
// Log all 404 errors
// Add to your .htaccess (you MUST put an absolute URL)
// ErrorDocument 404 /stats/stats.php
require "config.php";
function db_open () {
global $link;
global $sql_host, $sql_login,$sql_passe,$sql_dbase;
$link = mysql_connect($sql_host, $sql_login,$sql_passe)
or die ("Can't connect to $sql_host: $!\n");
mysql_select_db ($sql_dbase)
or die ("Can't select database $sql_dbase: $!\n");
}
function db_close () {
global $link;
mysql_close($link);
}
function mysql_protect($s) {
return "\"" . mysql_escape_string ($s) . "\"";
}
function db_add_record() {
global $sql_table;
global $_SERVER;
if (isset($_SERVER['REMOTE_ADDR']))
$remote_host = $_SERVER['REMOTE_ADDR'];
else
$remote_host = "-";
if (isset($_SERVER['HTTP_REFERER']))
$referer = $_SERVER['HTTP_REFERER'];
else
$referer = "-";
if (isset($_SERVER['HTTP_USER_AGENT']))
$user_agent = $_SERVER['HTTP_USER_AGENT'];
else
$user_agent = "-";
$request = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$a_remote_host = mysql_protect($remote_host);
$a_request = mysql_protect($request);
$a_referer = mysql_protect($referer);
$a_user_agent = mysql_protect($user_agent);
$q1 = "CREATE TABLE IF NOT EXISTS $sql_table ( time_str DATETIME, remote_host TEXT, request TEXT, referer TEXT, user_agent TEXT )";
$r1 = mysql_query($q1);
if (!$r1)
print "query failed : " . mysql_error() . " : $query\n";
$query = "INSERT $sql_table (time_str, remote_host, request, referer, user_agent) VALUES (NOW(), $a_remote_host, $a_request, $a_referer, $a_user_agent)";
$result = mysql_query($query);
if (!$result)
print "query failed : " . mysql_error() . " : $query\n";
}
# remove displaying of errors, warning ini_set is disabled on free.fr
error_reporting(0);
db_open ();
db_add_record();
db_close();
?>
The contents of config.php is simply the definition of the mySQL user and database variables.
The only other files in the module are: language.php, get.php, and index.php. The language and index files I've ruled out to have any involvement in this matter. The get.php file however could possibly be involved in this issue somehow. Here is the contents of get.php:
<?php
// location MUST BE either a relative url to a file, relative to this
// script (get.php) OR an absolute url (this should be avoided).
// Usage: replace
// <a href="../pub/fat-recover-0.1.tar.gz">
// by
// <a href="../stats/get.php?location=../pub/fat-recover-0.1.tar.gz">
// DO NOT OUTPUT SOMETHING BEFORE header();
function remove_dotdot($path)
{
while (is_integer($n = strpos($path,"/..")))
{
// extrat left & right part of the search string
$gauche = substr($path, 0, $n);
$droit = substr($path, $n+strlen("/.."));
// remove last / component, like "/stats"
$gauche = substr($gauche, 0, - strlen(strrchr($gauche,"/")));
$path = $gauche . $droit;
}
return $path;
}
if (isset($location))
{
header("Location: $location");
// Convert $_SERVER['PHP_SELF']
$url = parse_url($_SERVER['PHP_SELF']);
$path = dirname($url['path']) . "/" . $location;
// change $_SERVER['PHP_SELF']
$_SERVER['PHP_SELF'] = remove_dotdot($path);
}
require "stats.php";
?>
<html>
<head>
<title> Download error </title>
</head>
<body>
<p>
This script needs the <b>location</b> parameter in order to work.
</body>
</html>
I know that this could be audistat's fault, but I find it highly unlikely because it works fine when executed directly in the browser (as I mentioned earlier). My guess is that somewhere, the coppermine script(s) are being re-executed (possibly from audistat itself or from fatal errors within audistat). I don't understand why it would get this issue even when inserted
before any coppermine code in the index.php file! I hope this post gives you some idea of the workings of all this code. Please let me know if you need anything else. Thank You!