Alright, so here's the deal: I'm working on a basic site using PHP Includes so I don't have to update each page when making design changes. Well, It was all working fine until I decided to use various folders. For example, what used to be tools.php is now /tools/index.php. But, when using PHP include in the new /tools/index.php, I get problems since it looks for the include files (header.php, head.php, and footer.php) in /tools/. I tried using this: <?php include($DOCUMENT_ROOT . 'head.php'); ?> But it didn't work. Then I tried this: <?php include($DOCUMENT_ROOT . '/home/daniel59/public_html/head.php'); ?> Is there anyway of defining Document Root? But, anyways, I get no error messages. The problem is that head.php links to style.css, but, when I view the source for /tools/index.php, it looks for style.css in /tools/style.css. The file doesn't exist, of course, since style.css is located in /home/daniel59/public_html/style.css Ahhh, i'm confused
that's right. The problem is that you have relied on register globals, which are turned off in your enviroment (which is a good things) to find out why it wasn't working, just google register globals
Thanks. That worked for setting the home directory, but how do I fix the CSS problem? My CSS file (/style.css) has lines like: html { background: url(/img/bg.jpg) repeat; } The CSS file won't load since it is in head, and head is set to look for it at: <link rel="stylesheet" href="style.css" type="text/css" /> So, /tools/index.php is looking for the file tools/style.css, which doesn't exist. How can i fix that?
if its <link> try to follow your folder organization based on where it is <link> just use ../img/bg.jpg if going up one level and w/o ../ if under this folder... anyways its css just try to follow your folder organization.
That works, but is there a better way of doing this? Like, a way of getting head.php, header.php, and footer.php to automatically reset the paths to the root? EDIT: Just found out what I had to do. I had to put a slash in the paths. So, for example, in head.php, I had to change this: <link rel="stylesheet" href="style.css" type="text/css" /> to this: <link rel="stylesheet" href="/style.css" type="text/css" /> and it works. Thanks to everyone
you mean dynamic css? just one css file but is still compatible with other pages.. just put your css code into a php file with a <style></style> just insert a php variable inside it ie. #container .folder { background: url(<?=$_SERVER['DOCUMENT_ROOT']...?>/folder/image.jpg); }