Jez,
Yup, this is ok to use. There's a couple situations that this won't work,
though:
1. If your site is being hosted through the "User Directory" method. That
would make your web root here:
http://somedomain.com/~username/
However, your browser, will see the web root as:
http://somedomain.com/
and will request all files from the actual web root of the server. Note
that the browser doesn't care where your document is, it's all based on the
domain name.
2. If you're using any kind of path-style queries, this might confuse
things on your part, but is usually workable.
If you haven't seen many sites/tutorials using this technique, it's because
file system pathing seems to be the most misunderstood and yet most simple
aspect of computer operating systems. The idea of a root node escapes most
web designers (HTML authors). It also becomes an issue when developing web
sites on a desktop computer and uploading them to the server. Most people
need to keep checking and rechecking their work before they upload it to the
server. In this case, the local filesystem will map your files based on the
root of your drive. And, unless you're building your site right off the
root of your drive, your pictures aren't going to show up. But who needs to
check to make sure your pictures and style sheets are showing up when your
editing code that won't be visible until it's on the server, right? I think
the desire to "verify" all the linked resources on a web page stems from
people's lack of understanding of the file system in the first place.
On _all_ of the sites I design, I use either a full URL (
http://...), or the
absolute path to any outside resources for the same reason you had to use
two template files: the same HTML code may be served from any directory on
your site.
You should develop a sixth-sense for code duplication. When you start
noticing you have two of the same or two very similar pieces of code
existing on your web site accomplishing the same or very similar tasks, you
should have an alarm going off in your head: "There's gotta be a better way
to do this..."
I hope this helps,
Zac
I hope this helps,
Zac
"Jez" <je**********@btinternet.com> wrote in message
news:ad**************************@posting.google.c om...
I'm ashamed that I need to ask this question. I've been using PHP for
almost a year now, and have used HTML extensively in the last few
years.
Often, when I create a new site, I use include() to add an HTML header
at the top of the page and a footer (ususally including a menu) at the
bottom.
Up to now I've created two or more copies of each header and footer,
the only difference being the path to linked files. For example, in
the root directory I need to reference a stylesheet as
'style/screen.css', but in files within another directory I use
'../style/screen.css' or '../../style/screen.css'.
Now this is the part I'm ashamed about! I realised today that I could
just use '/style/screen.css' within the file in the root directory and
any other directory you care to mention. I've no idea how I missed
this and I'm sure I've never seen it in anyone else's HTML or in any
turtorials.
Can someone please confirm that it's ok to do this (i.e. one header
file and one footer file, using '/dir/file' as the link rather than
'dir/file' or '../dir/file')?
I hope this makes sense and that you can forgive my stupidity?
Jez