473,387 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

include() header and footer

Jez
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
Jul 16 '05 #1
4 4094
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

Jul 16 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Fri, 11 Jul 2003 14:14:28 -0600, "Zac
Hester" <ne**@planetzac.net> amazingly managed to produce the
following with their Etch-A-Sketch:
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.

@define(SITE_BASE, dirname(__FILE__));
@include(SITE_BASE . '/some_file.php');
Now it doesn't matter what the URL may be, as it deals with the
filesystem, not relative URLs =)
HTH.

Regards,

Ian

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPw8bdWfqtj251CDhEQKw0QCfSrrCvdSaASKp0GaeRD1PqF qBw5wAnRkZ
MdUm6p2q7AS18Id5zTbHl2M7
=mEuP
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #3
"Ian.H [dS]" <ia*@WINDOZEdigiserv.net> wrote in message
news:fp********************************@4ax.com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on Fri, 11 Jul 2003 14:14:28 -0600, "Zac
Hester" <ne**@planetzac.net> amazingly managed to produce the
following with their Etch-A-Sketch:
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.

@define(SITE_BASE, dirname(__FILE__));
@include(SITE_BASE . '/some_file.php');
Now it doesn't matter what the URL may be, as it deals with the
filesystem, not relative URLs =)


That's almost identical to how I set include/require paths in PHP (I never
did find the define() method a very elegant construct). However, it doesn't
address pathing in client-rendered HTML. PHP includes are not relative to
the domain name. PHP includes are _always_ based on the file system.
Images, style sheets, and JavaScripts are not based on the file system.
They are always based on the web site's "root" (domain name) since the
client has no way to reference the server's file system.

Good code snippet. Keep 'em comin'

Take care,
Zac
Jul 16 '05 #4
Jez
Thanks both for being so understanding!

Jez
"Zac Hester" <ne**@planetzac.net> wrote in message news:<3f********@news.enetis.net>...
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

Jul 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Fabri | last post by:
I'm trying to develop a way to include static files in htm pages with javascript. I'm trying to use XMLHTTP object this way: ...
3
by: Justin | last post by:
Currently I have a site template using classic asp that uses include files to seperate content from display. How can I do something similar in ASP.NET/C# code behind. Mainly I need to seperate...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
3
by: Dave | last post by:
Greetings, I am developing an internal web application. I would like to do some sort of method where I include a "header.aspx" and "footer.aspx" page in my code, so I don't need to include my...
4
by: Al Franz | last post by:
Editing a script that has a "sub printheader" and "sub printfooter" routine before and after it creates a web page with a message. I would like to customize this script so that I can have my own...
6
by: G | last post by:
Hello Friend, I am newly migrated from ASP to ASP.NET. When i am using ASP i used have a folder with named includes where i store header. asp and footer.asp pages. and i use <!-- #include...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
1
by: yemen2007 | last post by:
hi ever one. i have problem in my html file. i have header file , footer file, and index file. i want compile the header , and footer in the index file use include file put it is not work. this my...
25
by: Mark | last post by:
so, i'm making a website. let's say i have header.php, footer.php and content.php. now in index.php I simply want to include the 3 pages. easy enough to do. but let's say the user navigates to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.