Support => cpg1.3.x Support => Older/other versions => cpg1.3 Miscellaneous => Topic started by: Rims on June 16, 2004, 08:58:49 am

Title: PHP Fatal Error when adding simple php include!
Post by: Rims on June 16, 2004, 08:58:49 am
First I just want all those who contribute to the coppermine project, as well as general open source development, to know that I truly appreciate and admire all of your efforts.  Thank you all so very much. ;D ;D ;D ;D :D

Now, on to my question.  I am just trying to add basic php counter files into my standalone coppermine website.  I've tried several counters and all have seem to have fatal errors when implemented with my theme.php or index.php files.  All I am using is a single require("/myphpscript.php"); command. When I do so, I get the following error:

Fatal error: Cannot redeclare cpggetuserdata() (previously declared in /include/ in /include/ on line 44

 ??? ??? ???
I know, I know, you may be asking... "this is just another newbie who didn't read the documentation or other threads and I have to re-submit for the 50 millionth time the "custom header" thread! But guess what, I already looked at all that stuff and it sucks anyways!  >:( The code on that thread for custom headers doesn't even work. It gives this error (as reported already by other users):

Parse error: parse error, unexpected '(', expecting ',' or ';' in theme.php on line 822

Please understand that I have read and searched the documentation and threads.  Also please understand that I have been struggling with this for hours.  I looked in the counter php files and they do not call or declare your proprietary function: cpguserdata() function at all! I don't  understand why I would get a "cannot redeclare" error out of no where.  I don't have any good php editor or debugging programs so I have no idea what is going on. (Sorry about that one... didn't think we'd have to debug php code before posting threads on this forum).  Also, I don't think including a simple php file to all of this would cause so much damage (completely no coppermine page generation). Please help. And once again, I truly appriciate all that you've done with coppermine and the generous free support! Keep it up guys!  ;D

-Rims  :-\\

Title: Re: PHP Fatal Error when adding simple php include!
Post by: hyperion on June 16, 2004, 09:07:31 am
Nothing like a back-handed compliment to inspire great support.  ::)

For all that typing, you could have least given the name of the script you're trying to include, where you are trying to include it (given that our templating engine is not known to be forgiving), and possibly even attached the script to the post.
Title: Re: PHP Fatal Error when adding simple php include!
Post by: Rims on June 16, 2004, 06:58:41 pm
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 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):
Code: [Select]
// 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";

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");

db_close () {
global $link;

mysql_protect($s) {
return "\"" mysql_escape_string ($s) . "\"";

db_add_record() {
global $sql_table;
global $_SERVER;

if (isset($_SERVER['REMOTE_ADDR']))
$remote_host $_SERVER['REMOTE_ADDR'];
$remote_host "-";

if (isset($_SERVER['HTTP_REFERER']))
$referer $_SERVER['HTTP_REFERER'];
$referer "-";

if (isset($_SERVER['HTTP_USER_AGENT']))
$user_agent $_SERVER['HTTP_USER_AGENT'];
$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

db_open ();

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:
Code: [Select]

// 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">


function remove_dotdot($path)
    while (
is_integer($n strpos($path,"/..")))
// extrat left & right part of the search string
$gauche substr($path0$n);
$droit  substr($path$n+strlen("/.."));

// remove last / component, like "/stats"
$gauche substr($gauche0, - strlen(strrchr($gauche,"/")));

$path $gauche $droit;


if (isset(
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);


<title> Download error </title>


This script needs the <b>location</b> parameter in order to work.


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!
Title: Re: PHP Fatal Error when adding simple php include!
Post by: Nibbler on June 16, 2004, 08:07:43 pm
Code: [Select]
require "config.php";
Coppermine has a page called config.php, your counter looks like it is including that instead of it's own config.php. Try renaming both the file and the require line.
Title: Re: PHP Fatal Error when adding simple php include!
Post by: Rims on June 16, 2004, 10:39:46 pm
Nibbler, good call man, fixed the prior error but now there is a new one! Coppermine reports a "Critical Error: There was a critical error while processing a dabase query.  While under debug mode, the error message states:

"While executing query "DELETE FROM cpg130_banned WHERE expiry < 1087461219" on 0
mySQL error: No Database Selected"

File: /var/www/html/include/ - Line: 110

Do you think that the statistics program is somehow interfering with coppermine's access to the db? They use separate accounts to access separate databases... so I don't know why one would affect the other. Oh well. Also, I was having trouble editing the audistat scripts when using plain text editors such as notepad or wordpad.  I would get parsing errors when I saved the files with those editors.  I now got a php editor and all is well.. no parsing errors.  Hope this helps!

P.S.> Everything runs smoothly when I add the line to the index.php file! Without the include line in theme.php it works with no errors! Crazy! There must be some problem with the parsing of theme.php going on here.
Title: Re: PHP Fatal Error when adding simple php include!
Post by: hyperion on June 17, 2004, 12:14:43 am
Your 'basic' include is opening a secondary database connection.  Many of Coppermine's DB queries do not specify the MySQL resource as they expect to operate in isolation on a single connection. In this case, PHP cannot determine which resource it should be using because it has two to choose from without any user directives. This particular query is in include/ of Coppermine.
Title: Re: PHP Fatal Error when adding simple php include!
Post by: George83 on July 16, 2004, 03:06:48 pm
I've been having a similar problem as Rims. I am trying to connect to a CMS database to retrieve code used to display a java menu. I have already acheived this within the CMS template file, and it works ok, but it doesn't seem to work with Coppermine. Here is the code placed in theme.php:

function theme_display_javamenu()
   $data = $GLOBALS['data'];
   $pageid = explode("/", $_SERVER['PATH_INFO']);
   $pageid = 8;
   $where = " WHERE item_id=$pageid;";
   $err_msg = "You have no records at this level.";
   //***$data['navmenu'] = db_items_content($where, $err_msg);
   $javamenu = $data['navmenu'];
   return $javamenu;

The two includes are the files containing the db connect functions, and the db_items_content() function (the commented line), and so on. Removing the comment strokes causes a blank screen to appear, indicating that it can't find the function db_items_content(), i.e. the two files have not been included. I've already successfully placed other php functions which worked fine; the problem definitely lies in the includes.

I am running version 1.3.

Thanks in advance for your help.

Title: Re: PHP Fatal Error when adding simple php include!
Post by: Nibbler on July 16, 2004, 03:14:35 pm
where does $file_path come from ?  - doesnt seem to be defined.

Also change the includes to requires to make it give an error message.
Title: Re: PHP Fatal Error when adding simple php include!
Post by: George83 on July 16, 2004, 03:39:28 pm
Hmm, $file_path doesn't seem to be defined in any of the other CMS files. Removing it doesn't seem to make any difference; I still get a blank page.

I replaced 'include' with 'require', but I still get a blank page...
Title: Re: PHP Fatal Error when adding simple php include!
Post by: tickle on July 28, 2004, 03:47:24 pm

I got version 1.3.1 yesterday and had the same problem as you guys are having.  The error does say what the problem is.

It says it cannot find the file because it is looking for your include folder (specified in the php info file) i.e. mine was pointing to my public html folder, but obviously where the include folder was located in my copper directory. Changing where locates the include files will not help as the install writes to this folder.

I solved this by installing coppermine into my publichtml folder i.e. so that the include folder was in my root. This means that on installation the config is written to the correct location and now everything works fine.

I could have changed my default include directory on the php setup my my provider is uncontactable at the moment.

Hope this helps.   ps.  If you want to have coppermine in a different directory, you could try editing the BEFORE you upload it. i.e. changing the include from ../include   to the full path i.e. for me it would be include ('')

Hope this helps i couldn't find a solution anywhere.

Title: Re: PHP Fatal Error when adding simple php include!
Post by: tickle on July 28, 2004, 05:34:23 pm
Really sorry wrong board......     have posted again......   here