Page 1 of 1
include(); problem
Posted: Mon Oct 03, 2005 9:28 am
by someberry
Hi,
Whenever I try and do:
Code: Select all
include('http://www.domain.com/header.php');
It adds all of the layout styles, but seems to ignore the PHP in that file. If I do:
Everything works fine. However, I need to use the full URL, as I need to call the header from other directories (hence cannot use the local address), do I need to set an include path before executing the include() to make it work correctly?
Thanks for the help,
Someberry.
Posted: Mon Oct 03, 2005 9:36 am
by feyd
you don't need to use a URL, which will generate a subrequest and have php process that file returning the results to this script which will process it. Relative or absolute paths are preferred (or potentially setting include_path).
../sibling/child/script.php will look for script.php in the parent directory's 'child' directory under the 'sibling' directory, for instance.
Posted: Mon Oct 03, 2005 9:47 am
by $var
you could also use $_SERVER['DOCUMENT_ROOT']; to set a path.
Posted: Thu Oct 06, 2005 4:47 pm
by someberry
Ok, I managed to get it working using the ../../ technique - thanks for that. However, I have stumbled upon another problem.
I want to include a header, that header has the session_start(); in it. As you well know, session_start(); has to be called first so at the top of the index.php script, I have:
Code: Select all
<?PHP include('../../test/header.php'); ?>
However, I am using this as a test directory for the new layout which I am going to transfer in a couple of weeks. As it is, it isnt very directory friendly, when I transfer the files, I am going to have to change every file so that it looks in the right directory for the header and footer files. Is there anyway that I can get the path leading up to, but not including the file name, so for instance:
/home/my_space/public_html/test/
I looked through the $_SERVER variables, but it doesnt appear to be much use. Is there anyway I can get it, or anyway I can make the script in Apache, and then use it that way?
Thanks,
Someberry.