Forum Moderators: coopster
In header.php I have the tag
<link href="../css/style1.css" rel="stylesheet" type="text/css" />
in file1.php I have the line
require_once("master/header.php"); //everything works fine
in file2.php I have the line
require_once("../master/header.php"); //everything works fine
in file3.php I have the line
require_once("../../master/header.php");
The problem I find is that the css stylesheets don't get loaded. The header page loads, but none of the styles are there. I think it has something to do with everything being in different folders, and that I am going up two directories but I have no idea how to fix this. Can anyone help? Thanks,
your header.php file is looking for the css file relative to that location i.e.
root/folder1/css/style1.css and not in
root/css/style1.css
This thread may help you resolve this
[webmasterworld.com...]
Hope that helps.
Use a starting slash for client side, full server path for server side.
In client side - in the browser pages, whatever you can view source and see - this always means "start at the domain root and look along this path"
/path/to/css/style.css
CSS looks for paths [as in, url(/images/image.jpg)] relative to the css file itself, external Javascript relative to the document including it - in either case you can move that css file seven directories deep, and the above will always work so you don't have to futz around with the ../../../dot-toothpick syndrome.
For PHP includes, it's not a URL, it's a system path. So for larger systems define domain root as a constant
define('DOM_ROOT','/var/www/path/to/example.com');
or for small systems,
include_once(('/var/www/path/to/example.com/inc/include.php');
OR use environment variables.
include_once(DOM_ROOT . "/include.php");
Where people get confused is they continue to struggle with the relative url/path, and they look so much the same, begin to think they are the same thing. They are not.
* Why not full URL? When you go to replicate pages/code, you can nit-pic around doing a search and replace of the full URL's in your documents, or you can just MOVE them without messing with it. /path/to/css/style.css can move to example.com or example2.com and still work, with the full URL you have to change all your files.