I have a folder, blacknova, which has in it a header and a footer file. I have made a sub-folder, admin, and I'm calling the header and footer files like this: include("../header.php"); include("../footer.php"); PHP: In general, this works. However, the are some things (eg images) in the header and footer files that aren't being called because the path, although right for the blacknova folder, sin't right for the admin folder, eg images/bgoutspace1.gif Code (markup): Is there any way of altering the paths so that they will be correct for both blacknova and blacknova/admin folders, or will it be necessary to make new header and footer files for the admin folder?
I'm not sure if your server would support it but try using absolute web address eg : include("http://yourdomian.com/blah.php"); PHP: if it works, well and good for you
The working directory of the PHP script isn't necessarily the web root. For files referenced by an end user's browser (images, stylesheets, scripts, etc.), always make them relative to the web root: <img src="/images/foo.jpg" /> Code (markup): Referencing included files from the web root (the first slash) ensures the browser knows where they are, regardless of where the page being viewed resides.
I'd prefer not to use absolute web addresses; I may distribute the script and I'd rather the locations weren't pointing to my server. Regarding making them relative to the web root, that probably also won't be good for working on other servers; also, it doesn't seem to work for the admin sub-folder.
The easiest thing would be to add this to the header file's <head> section <base href="http://www.yoursite.com" /> HTML: Obviously that's useless when you're redistributing your code to other sites, so you could use <base href="http://<?=$_SERVER["HTTP_HOST"]?>" /> HTML: Failing that, you could always set a path variable to prepend when necessary, e.g. in the admin files, do this <? $strPath = "../"; include("../header.php"); include("../footer.php"); ?> PHP: and in the header.php do this <img src="<?=$strPath?>images/bgoutspace1.gif" HTML: Strictly, you should set $strPath = "" in your non-admin pages, but it will work fine without it as long as notices aren't shown.
l0gic is right. So there are two types of path - php & html. For html link use the ultimate path i.e. src="/images/image.gif" (so it starts with "/" and has a full path to the image. When it comes to php includes user the following include $_SERVER['DOCUMENT_ROOT']."/includes/file.php"; that will give u an ultimate path for php files