This is CMC
-> Lars
-> Professional
-> WWW-HTML
-> webpro.htm
More Complex Web Programming
All the examples on the previous page were simple static pages,
i.e. pages that you write once, the description of the page is in a
single text file, and every time you bring up the page, it looks the same.
This type of web site is fairly simple to build, and for many people,
this is all they ever need to know.
But static pages have their limitations, and in the following we will
show you some way to go beyond those limitations.
Server-side #include files: .shtml
When you build a large website for a business, you need to
- maintain a distinctive look to your pages
- maintain that distinctive look in a uniform manner on all
pages (often hundreds of pages)
- make it simple to maintain (i.e. when you write a new page,
it should only take a few keystrokes to make it fit the
style pattern of the website)
- make it easy to change the style (i.e. when you decide to change
the color scheme, for the style of the page headings, you should
be able to edit only one or two files and have the change
take effect immediately).
To maintain a unique and uniform look on all pages, typically involves
putting 10-20 lines of HTML at the top and bottom of every page.
This can be done in two ways:
- You can write a program (typically in
PERL) that will "walk the file tree"
and make sure that the current version of your standard header and footer
is inserted in every HTML file.
The website that I built for
California Seafood Council
was done that way.
- You can use a webserver that supports server-side include files
and add the following lines to each HTML file:
< !--#include virtual="/header.htm"-->
...
< !--#include virtual="/footer.htm"-->
This causes the server to replace each of these HTML comment lines
with the contents of the file indicated. Most web servers can do
this (and especially Apache
which is the webserver used by most ISP hosting services); you
just have to give the file containing the page a name that ends in
.shtml (instead of .htm or .html).
The website that I built for
UC Wireless (with help from FatEyes)
is built in this way.
The advantage of using the PERL wrapper is that you can preview the files
from your local hard drive. When you use server side includes, they only
work when they are being served by a web server. And there are
servers that do not support server side include files for personal
websites under non-business accounts (because they need a technical
reason to justify charging $100/month for a business account instead
of $20/month for a personal account).
Server side includes also allow you to do a few other nifty tricks,
such as generating HTML from PERL scripts embedded in the page.
CGI-BIN scripts
Web pages do not have to be static pages that always look the same,
they can also be the output of a program that runs every
time you call up the page. This can be used to implement many kinds
of programming applications from online shopping to discussion groups.
As always, when you go from writing text files to writing programs,
you are increasing the level of complication, and you are now taking
on responsibilities of debugging your programs. Because errors in
programs might take down the whole webserver, many server sites
do not allow users to put in this kind of programs.
This type of programs are called CGI programs. CGI is short for
Common Gateway Interface.
- Bulletin boards/discussion groups
-
http://www.chem.hope.edu/~discus.
Generally free (read their license info).
Cookies
In general, displaying a web page is a simple command-response handshake.
- The user requests a page named "http://www.somehost.com/page.html"
- The browser connects to TCP port 80 (http) of the server "www.somehost.com"
and says "Please give me the page named /page.html"
- The server returns the HTML file of the page.
If the user wants another page, it is a new request and may in fact be
served by a different copy of the server program (and the server may have
answered requests from 20 other people in between).
Cookies are a way to pass information about a user between the several
server instances that may be talking to the user. The server stores
a short piece of (possibly encrypted) text to the browser, and
when the browser connects again, it passes the text along with the
page request.
For more information about how cookies work, read
this article.
$Log: webpro.htm,v $
Revision 1.3 2001/10/26 13:28:29 lars
Replaced CMC -> Beagle-Ears
Revision 1.2 2001/01/15 07:06:31 lars
*** empty log message ***
Revision 1.1 2000/08/25 19:26:58 lars
Add reference to article about cookies.
Remove bad link on "spectacular websites" page.