Problem Locating Header/Footer Files

jeeter

New Member
Messages
9
Reaction score
0
Points
0
Hi,

I'm running into an issue when I'm including my header.php and footer.php into my web pages. The problem is that for each web page I have to specify how far back into the directory the page needs to go to reach header and footer.

Example: Includes for a page located in http://mysite.x10hosting.com/dev/index.php
Where header.php and footer.php are located at http://mysite.x10hosting.com/
PHP:
<?php include('../header.php'); ?>
/*Body*/
<?php include('../footer.php'); ?>

What I would like to do(and thought would work for getting back to the root directory) is this:
PHP:
<?php include('/header.php'); ?>
/*Body*/
<?php include('/footer.php'); ?>

Unfortunately when I attempt to run a page using the 2nd method there I get an error saying that "/header.php could not be found in the directory /dev/index.php".

Any help would be very much appreciated. It's such a bother to have to look and see how many directories back I need to go in order for my includes to reach the main directory and grab those damned header/footer files...

Thank you,
Jeeter
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
you can use chdir('/path/you/want/')

you have to use the full path, ie /home/user/public_html
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You could use virtual() to include the files. You could also add the document root to the include_path, allowing you to use "include('header.php')". Slightly better would be to create a directory named (eg) "include" in public_html (or wherever) and put the path to "include" in the include_path. That way you can separate pages from the files your site uses internally.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
I simply do a
PHP:
define('ROOT', '../');
and include files doing
PHP:
<?php include(ROOT . 'header.php'); ?>
/*Body*/
<?php include(ROOT . 'footer.php'); ?>
 
Top