PDA

View Full Version : How to include global.php from up two directories and down one directory


RoxUrSox
08-06-2009, 12:54 AM
I got two files

/home/flowgrap/public_html/ig/cp/includes/cookie.php
<?php // session is already started in file that includes this one
if ( !isset($_SESSION['user']) ){
// ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/home/flowgrap/public_html/ig/forums/');
// echo "<!-- " . ini_get('include_path') . " -->";
// $path = "/home/flowgrap/public_html/ig/forums/";
// set_include_path(get_include_path() . PATH_SEPARATOR . $path);

include("global.php");

$userid = $bbuserinfo['userid'];
if ( $userid > 0 ) {
$_SESSION["user"] = $bbuserinfo['username'];
}
}
?>
I tried setting the include path, and it showed up in the error saying the include path the forums correctly, but it still gave me:
Warning: require_once(/home/flowgrap/public_html/ig/cp/includes/init.php) [function.require-once]: failed to open stream: No such file or directory in /home/flowgrap/public_html/ig/forums/global.php on line 20

Fatal error: require_once() [function.require]: Failed opening required '/home/flowgrap/public_html/ig/cp/includes/init.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/flowgrap/public_html/ig/forums') in /home/flowgrap/public_html/ig/forums/global.php on line 20

/home/flowgrap/public_html/ig/forums/global.php
The Normal VBulletin 3.8.1 global.php Code here


So I understand that it's trying to require the files from inside my current directory, even though I changed the include path. How do I fix it so that the global.php loads the vbulletin files in the vbulletin directory, instead of the current one?

1Unreal
08-06-2009, 06:02 AM
include("./global.php");

Dismounted
08-06-2009, 06:08 AM
$curdir = getcwd();
chdir('/home/flowgrap/public_html/ig/forums');
require_once('./global.php');
chdir($curdir);

RoxUrSox
08-08-2009, 06:42 PM
$curdir = getcwd();
chdir('/home/flowgrap/public_html/ig/forums');
require_once('./global.php');
chdir($curdir);

Thanks, your code works. I did try chdir before, but apparently it requires the full path, didn't know that :P