Having the same hierarchy:
Code:
+ FOLDER1
- file1.php
+ FOLDER2
+ FOLDER3
- file2.php
+ FOLDER5
- file3A.php
+ FOLDER4
-file3B.php
but this:
PHP Code:
/* file1.php */
$var = "foo";
function include_file($file_path)
{
require_once($_SERVER['DOCUMENT_ROOT'].$file_path);
}
include_file('/FOLDER1/FOLDER2/FOLDER3/file2.php');
/* file2.php */
include_file('/FOLDER1/FOLDER2/FOLDER3/FOLDER5/file3A.php');
include_file('/FOLDER1/FOLDER2/FOLDER4/file3B.php');
I get the following:
file1.php // $var is available and file2.php is included
file2.php // $var is not available; $GLOBALS['var'] is available; file3A.php and file3B.php are included
file3A.php // $var is not available; $GLOBALS['var'] is available;
file3B.php // $var is not available; $GLOBALS['var'] is available;
In the real application I'm not having access to the vars if not through $GLOBALS, is that because I must pass references to all set vars to the function?, if that's so, how could I go around this without that function?
I basically need to let files have access to any file in anyway without loosing references. Thanks for replying.