Server-side Scripting
What the heck is Web Programming anyway?
At some point along the way webmasters around the net realized that HTML
(1) was too limited to do many of the things that they
wanted to accomplish.
How could a webmaster display the current time and date on every page
accessed by a client? How could she collect information about clients
who were accessing her web site? How could she create a web site that
was more than just an information warehouse, but a meaningful and dynamic
conversation?
Certainly, HTML was great for distributing "pre-prepared" web pages on
request. A client would use a web browser to contact a web server and use
HTTP to ask the
web server for a specific HTML document. (2) The web server would then send the requested document back to
the web browser which in turn, would display the document as defined by
the HTML to the client.
Pretty nifty really, and far superior to older technologies like gopher
and ftp. However, the interaction between the client and the server was
still extremely trivial. The server could only provide HTML documents
which had been specially encoded by a webmaster, and which had been placed
in certain publicly-accessible directories. The interaction between web
browser and web server was pretty mind numbingly simplistic and the
coolness of surfing through hyperlinks quickly became droll.
HTML fell short of anything truly "dynamic".
For example, to put the current date on every page using only HTML would
require a webmaster to manually edit every file, every day. As you can
imagine, this got tiring very quickly for sites with more than 5 pages.
Webmasters needed a way to have HTML pages created and modified
"on-the-fly," with information which could change weekly, daily, by the
second, or for each and every request. And they needed those pages to be
modified automatically, without their constant oversight.
As it so happens, the hardware which web server software runs on typically
has quite a few resources which can be utilized to help solve these
problems. Not only do servers have processing power to spare, they also
have a battery of applications (such as e-mail, database manipulation, or
calendaring) already installed and ripe for utilization.
And thus was born CGI (Common Gateway Interface). (3)
CGI: The Birth of Server Side Web Programming.
As with most computer jargon, the term Common Gateway Interface can be
fairly meaningless at first glance. So, before getting into what CGI can do,
let's take a moment to define what CGI actually is.
- Common - CGI programs can be written with many languages. CGI
can be programmed in C, C++, Java, Perl, Visual Basic, or any other
language which can accept user input, process that input, and respond
with output.
Further, CGI works with many different types of systems. CGI works
on Mac, NT, Windows, OS2, Amiga, UNIX, and pretty much every
operating system which runs web server software.
By the way, if you use a "platform independent" language like Perl or
Java to write your CGI script, the exact same CGI script can be moved
directly from one platform to another without it breaking!
(4)
- Gateway - CGI's usefulness does not stem from what it can
accomplish by itself, but what it can accomplish by making partnerships
with other resources.
I often see CGI as a middleman or a translator whose job it is to help
more powerful resources like databases, graphics generation programs,
or network applications talk to each other and work towards a common
solution.
CGI is the gateway between the lone web surfer with her trusty web
browser and the vast web of computers (each with their own
specific language and protocols) and computer programs (each with their
own interfaces and methods of output).
CGI translates between the language the client speaks (perhaps HTMLized
English) and the multitude of languages spoken by the resources the
client wants to utilize (such as SQL for relational databases). This
is a crucial job, cause let me tell ya, my grandmother does not want to
know how to speak SQL when she is browsing the web!
- Interface - CGI is not a language. Neither is it a
program. CGI is a standard of communication, a process, an interface
which provides well-defined rules for creating partnerships. The
benefit is that if everyone follows the rules of the interface, then
everyone can talk to each other. Thus, typically we say that we
write "CGI programs" or "CGI scripts" which perform the functions of the
common gateway interface.
Let's look at the CGI processes in the following chart.
Okay, so that is probably a lot of abstract stuff to take in all at once,
especially if you have not worked with CGI already. So let's back up a
minute and go over what CGI is by looking at it in the wild. Let's look
at some examples of CGI in action.
You can easily see that CGI makes for a much more profound surfing
experience allowing web sites to offer useful and compelling services to
surfers who may be interested in information or products offered. (5)
However, there is a dark side!
Footnotes
- The Web Developer's Virtual Library has an excellent
HTML
Primer if you need a refresher on what HTML is! But basically,
HTML (Hyper Text Markup Language) is a way of describing how a web
browser should display text and images. HTML codifies page layout
into a series of instructions called "HTML tags". The job of Web
Browser programs is to translate ugly HTML instructions into the
beautiful web pages we see while surfing.
- Okay so there are quite a few jargon words in that
sentence which might need quick explanations.
In this column we will use the word "client" to refer to a person
who is using a "web browser" program like Netscape Navigator or
Internet Explorer to display HTML documents received from a "web
server".
A web server is a combination of hardware (an actual computer which
stores all of the HTML files) and software (the program which listens
for web browser requests and utilizes the hardware resources to
fulfill those requests).
Web browsers and web servers communicate using HTTP (Hyper Text
Transfer Protocol) which provides a communication standard for efficient
and intelligible dialog. Essentially HTTP allows a web browser to
contact a web server somewhere on the web and ask for a specific
document (or resource). It also allows the server to send the
requested document (or execute the resource) back to the web browser.
- Truthfully much of what is done by CGI can also
be done using SSI
(Server Side Includes) which is a service provided
by web server software in which certain HTML comment tags can be used
to execute commands. SSI will not be covered this month since it
demands its own article, however, for the purposes of this
introduction, SSI programs are similar enough in theory to CGI programs
that they can be thought of as the same thing.
- When you get some software for your computer and
you have to get the special "Mac Version" or "Windows Version", you
are getting a "platform dependent" program. Unfortunately, when
you move from being a PC user to being a Mac user, you have to buy
all new programs because the programs you bought for Windows will
not work on Mac. The beauty of web programs is that they are
typically "platform independent" which means that you can run them
anywhere. Whether you use a PC, Mac or Unix box, the programs will
work just fine.
- CGI is not the only form of server-side scripting
available, of course. For example, Netscape's Live
Wire is an online development environment for Web site
management and client-server application development. It uses JavaScript,
Netscape's scripting language, to create server-based applications
similar to CGI programs. Unlike CGI programs, however, LiveWire
applications are closely integrated with the HTML pages that control
them. However, non-CGI server side strategies are best covered in
their own article.
|