PHP Fatal Error when adding simple php include! PHP Fatal Error when adding simple php include!
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

PHP Fatal Error when adding simple php include!

Started by Rims, June 16, 2004, 08:58:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rims

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/init.inc.php:44) in /include/init.inc.php 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  :-\\



hyperion

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.
"Then, Fletch," that bright creature said to him, and the voice was very kind, "let's begin with level flight . . . ."

-Richard Bach, Jonathan Livingston Seagull

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.mozilla.org%2Fproducts%2Ffirefox%2Fbuttons%2Fgetfirefox_small.png&hash=9f6d645801cbc882a52f0ee76cfeda02625fc537)

Rims

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($path0$n);
        
$droit  substr($path$n+strlen("/.."));

        
// remove last / component, like "/stats"
        
$gauche substr($gauche0, - 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!

Nibbler

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.

Rims

#4
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/functions.inc.php - 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.

hyperion

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/init.inc.php of Coppermine.
&quot;Then, Fletch,&quot; that bright creature said to him, and the voice was very kind, &quot;let&#039;s begin with level flight . . . .&quot;

-Richard Bach, Jonathan Livingston Seagull

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.mozilla.org%2Fproducts%2Ffirefox%2Fbuttons%2Fgetfirefox_small.png&hash=9f6d645801cbc882a52f0ee76cfeda02625fc537)

George83

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()
{
   include($file_path."../../../cmsadmin/dotwidgetc_config.php");
   include($file_path."../../../includes/common.inc");
   $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.

George

Nibbler

where does $file_path come from ?  - doesnt seem to be defined.

Also change the includes to requires to make it give an error message.

George83

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

tickle

Hi,

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 init.inc.php 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 init.inc.php BEFORE you upload it. i.e. changing the include from ../include   to the full path i.e. for me it would be include ('http://tom.drumandbass.ru/clubpictures/copper/include')

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

Tom

tickle