Here is my folder layout: main --folder: pages ----file1.php ----page.php ----filehead.php ----folder: lists ------file2.php I want to include the contents of 'filehead.php' in the files 'file1.php' and 'file2.php'. I used the PHP include() command. In filehead there are links to other pages with the format ../page.php. The problem arises when I include 'filehead.php' in 'file2.php' because it thinks that ../page.php means something like: ../lists/page.php. How can I fix this error without making a new 'filehead.php' file especially for the lists folder? If you need anymore information just ask. Thanks! ~Imozeb
first, I assume that you understand PHP pretty well. in your file1.php use this code to include the filehead.php <?php include("filehead.php"); ?> PHP: and for the file2.php use this code. <?php include("../filehead.php"); ?> PHP:
Okay. I know how to do that, but how do I make the links in 'filehead.php' link to the file 'page.php' from both 'file1.php' and 'file2.php' because if I include the links in 'file1.php' as 'page.php' then when I include 'filehead.php' links in 'file2.php' it does not work because the links are for 'page.php' not for '../page.php'. Is there anyway I can fix this or is there another way I could include files in a PHP file? Please help, I've been trying everything I know! ~imozeb
try to define the path on file2.php so it's point to the files on parent directory. <?php define('BASE_PATH',realpath('.')); ?> PHP:
You know I've always used this myself, so instead I always used a database. I made a class file for this so that I dont have to query it all the time, where I could simply call a function for this and then include the directory. You should do that, other than this.. Use the simple 2 dots to escape the current directory to the one thats closer to the top directory. ../directory