tags:

views:

16

answers:

1

I have a html_headers.inc.php script that I want to include in every script on the site, to drop in a style sheet, the headers of the page, etc.

It refers to main.css as the stylesheet to use, but when I get down into a subdirectory, i.e. /foo, the link obviously breaks because it's pointing to main.css and not ../main.css. What's the best way to guarantee it always points toward that top-level where main.css lives? I've got

http://<?= $_SERVER['HTTP_HOST']; ?>/main.css

working, but it seems like there must be a more correct way.

+3  A: 

What about using "/main.css"

"/" refers to the base of your domain, and main.css to the file you want.

And, if one day you start putting your CSS into sub-directories, you can just add those to the path, like "/styles/main.css".
Same will work for JS files, images, ...

Pascal MARTIN
That works! Thanks!
Matthew
You're welcome :-) Have fun!
Pascal MARTIN