PDA

View Full Version : PHP: includig global.php outside of forum


Swedie
01-15-2004, 12:34 PM
Okay, including the global.php file isn't all that hard, but what I've noticed is a problem is that ANYTHING put in a $string before I include the global.php is removed / dumped and ... NULL... this messes up my scripts. I need to figure out a way of keeping the value of a $string I set before the inclusion..

please help me with this.

Okay, to detail the issue a little, here is my header.php file:

$currentdir = $_SERVER['DOCUMENT_ROOT'];

chdir("/home/sporthoj.com/www/www.sporthoj.com/forum");
require("./global.php");
if($currentdir) {
chdir("$currentdir");
}
else
{
chdir("/home/sporthoj.com/www/www.sporthoj.com");
}

You might see what I am trying to do. I am including the global.php file from other directories and need to return back to the original directory. but it just don't work because the value of $currentdir is set to NULL after the global.php file has been loaded.

How I know:
Because if I echo $currentdir before requre() there is a value inside it. But when I echo AFTER require, the value of $currentdir is no longer present.

NTLDR
01-15-2004, 12:38 PM
define('CURRENT_DIR', $_SERVER['DOCUMENT_ROOT']);

chdir('/home/sporthoj.com/www/www.sporthoj.com/forum');

require('./global.php');

if(CURRENT_DIR) {
chdir(CURRENT_DIR);
} else {
chdir('/home/sporthoj.com/www/www.sporthoj.com');
}


Not sure why you have the if statement as its not really needed. Anyway the above example will work as vB unsets the majority of variables at the start of the script for safety reasons.

Swedie
01-15-2004, 02:26 PM
thanks, but CURRENT_DIR is empty when I try to echo it with: echo CURRENT_DIR();
It gives me: Fatal error: Call to undefined function: current_dir() in /home/sporthoj.com/www/www.sporthoj.com/top.php on line 16

and I am not returned to the original dir.

so apparently vB also unsets any define values as well?

I am using vBulletin v3.0 RC2.

There has to be a way?

NTLDR
01-15-2004, 02:27 PM
CURRENT_DIR isn't a fucntion, its a constant, echo CURRENT_DIR; will work :)

KuraFire
01-15-2004, 02:36 PM
thanks, but CURRENT_DIR is empty when I try to echo it with: echo CURRENT_DIR();
It gives me: Fatal error: Call to undefined function: current_dir() in /home/sporthoj.com/www/www.sporthoj.com/top.php on line 16

and I am not returned to the original dir.

so apparently vB also unsets any define values as well?

I am using vBulletin v3.0 RC2.

There has to be a way?
constants are CaSe SenSiTive. A define() is a creation of a CONSTANT, and thus don't treat it as a function (never add () after it), as well making sure you're using the exact same, case-sensitive name.

Swedie
01-16-2004, 01:15 PM
constants are CaSe SenSiTive. A define() is a creation of a CONSTANT, and thus don't treat it as a function (never add () after it), as well making sure you're using the exact same, case-sensitive name.
Thank you for clearing that up.

I have now noticed that since I do:
define('CURRENT_DIR', $_SERVER['DOCUMENT_ROOT']);
inside the include file that is outside of the directory that I am actually in, the value of CURRENT_DIR is the one that my header.php file is in... always.

Is there a way to go around this or would I have to specify the value of CURRENT_DIR inside the file that calls the header file? That would be a pain in the butt and would make the function kind of worthless for me.