saturnstroll Posted February 19, 2008 Share Posted February 19, 2008 Hello, I successfully used the include function on http://mrconcreteblockhouse.com/index.php which has 2 include files: <?php include("top.php"); ?> and <?php include("bottom.php"); ?> The index works just fine. However when I try to put the same code in http://mrconcreteblockhouse.com/f/found ... b.html.php it doesn't work. I then tried placing copies of top.php and bottom.php in the same /f/ directory, but still doesn't show the top or bottom. Then I tried defining the path to the directory: <?php define('PATH', '/www/mrconcreteblockhouse/httpdocs/'); ?> <?php include(PATH . "top.php"); ?> Still doesn't work. Any ideas? Quote Link to comment Share on other sites More sharing options...
chronister Posted February 19, 2008 Share Posted February 19, 2008 This is the way I include things I want showing on every page regardless of where it lives in the directory structure. <?php include($_SERVER['DOCUMENT_ROOT'].'/top.php'); include($_SERVER['DOCUMENT_ROOT'].'/bottom.php'); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Your include file is assuming the file is on the same level. If your script is in another folder, you have to adjust your include to allow for that. If it is in the same folder, there is no reason why it wouldn't work. Quote Link to comment Share on other sites More sharing options...
saturnstroll Posted February 19, 2008 Author Share Posted February 19, 2008 Your include file is assuming the file is on the same level. If your script is in another folder, you have to adjust your include to allow for that. If it is in the same folder, there is no reason why it wouldn't work. Exactly. I have it top.php and bottom.php sitting in the same directory /f/ I don't see why it's not working. Quote Link to comment Share on other sites More sharing options...
saturnstroll Posted February 19, 2008 Author Share Posted February 19, 2008 This is the way I include things I want showing on every page regardless of where it lives in the directory structure. <?php include($_SERVER['DOCUMENT_ROOT'].'/top.php'); include($_SERVER['DOCUMENT_ROOT'].'/bottom.php'); ?> Hi, so if I cut/paste that will it work, or do I need to make modifications, or move files to a particular directory/area? Quote Link to comment Share on other sites More sharing options...
chronister Posted February 19, 2008 Share Posted February 19, 2008 if top.php and bottom.php are in the root directory of your site they will work. Basically, the directory that serves your index page. If they are not there, then either move them there or adjust the path to them. the superglobal $_SERVER['DOCUMENT_ROOT'] starts in the directory where your index page is served from. Nate Quote Link to comment Share on other sites More sharing options...
ILYAS415 Posted February 19, 2008 Share Posted February 19, 2008 hmmm i would try.... include "../top.php"; //means go up a level and find top.php include "../bottom.php"; If that doesnt work tell us the error wihch your getting Quote Link to comment Share on other sites More sharing options...
chronister Posted February 20, 2008 Share Posted February 20, 2008 hmmm i would try.... include "../top.php"; //means go up a level and find top.php include "../bottom.php"; If that doesnt work tell us the error wihch your getting But if the page that is calling these is /services/some_service/index.php that will look in /services .. if these files are located at /top.php & /bottom.php then the ../ method will fail. I fought with this exact thing for a long time. I wanted to find the equivalent of HTML's / "start at root" type path. Using $_SERVER['DOCUMENT_ROOT'] was exactly that. Calling this with every include stopped every single include problem I had experienced. Just my $.02 Nate Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 For every page that calls top.php/bottom.php use the relative path. So if you are in /index.php use include('top.php'); If you are in /subdir/page.php, use include('../top.php'); Then, inside top.php and bottom.php, if you need to include/access other files, use this method of getting to them: top.php <?php //include the functions include(dirname(__FILE__).'/functions.php'); ?> This way no matter where you include top.php from, it will work. Quote Link to comment Share on other sites More sharing options...
saturnstroll Posted February 20, 2008 Author Share Posted February 20, 2008 Yes, I'm also looking for the html equivelant/solution. So I tried the "../" which looks like this on /f/foundation-hub.html/ <?php include ("../top.php"); ?> No go. Maybe I didn't type it correctly? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 what do you mean HTML equivalent? I see no HTML Maybe you are looking for http://www.w3schools.com/tags/tag_base.asp ? Quote Link to comment Share on other sites More sharing options...
saturnstroll Posted February 27, 2008 Author Share Posted February 27, 2008 Problem solved. =) Once I renamed the foundation-hub.html to foundation-hub.php, everything works with copies of top.php and bottom.php in said subdirectory. Thanks to all for your input. Quote Link to comment Share on other sites More sharing options...
chronister Posted February 29, 2008 Share Posted February 29, 2008 what do you mean HTML equivalent? I see no HTML Maybe you are looking for http://www.w3schools.com/tags/tag_base.asp ? In HTML, you can denote a path as /path/to/a/folder. By using the / at the start, this tells HTML to start at root. In php the closest thing I found is $_SERVER['DOCUMENT_ROOT']. This allows me to add that to an include path and I NEVER have to worry about the path being wrong. I fought with this for a LONG TIME. This is the best solution I could come up with. Nate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.