Before
Web-Embedded Programming
A few years ago, Web programming started out with the Common
Gateway Interface,
or CGI. Here's a quick review of the basics concepts of CGI.
- When a user makes a CGI request of a Web server, something in the
URL will tip off the server to process it as a CGI request. The hint
in the URL could look like one of the following examples.
- The URL requested by the user is in a /cgi-bin/
directory: http://www.someWhere.com/cgi-bin/randomCGIprogram
- The Web server might be configured to automatically recognize
certain file extensions as being CGI executables: http://www.erehwon.org/goSearch.py
.py commonly denotes Python
programs, another popular language for Web programming.
- The file extension might be a "generic" CGI
extension: http://www.xyz.net/doSomething.cgi
- In these cases, the Web server "hands off" to a program
specified by the URL, spawning it as a child process and providing
it with the information it needs to be a "Web program":
generally environment variables (ie, QUERY_STRING)
and Standard
Input (STDIN).
- The program will run and produce information, which it sends to Standard
Output (STDOUT).
Usually, the program will then create a minimal amount of HTTP
header information, at the very least, as part of its Output.
- The Web server will "capture" the STDOUT
stream and redirect it to the user via the Web. The user's browser
will interpret the information according to the HTTP header. This
will usually be HTML text, but CGI programs can just as easily
create byte streams to be reconstructed as JPEG images or RealAudio
feeds.
A simple C program:
#include <stdio.h>
int main () {
print("Hello,
world!\n");
}
which we can turn into a simple CGI program by simply adding an HTTP
header:
#include <stdio.h>
int main () {
print("Content-type:
text/plain\n\n");
print("Hello,
world!\n");
}
Now all that's left to do is compile this code and put the resulting
binary in my Web directory structure and then set permissions
appropriately.
NOTE: print("Content-type:
text/plain\n\n"); should look like the Perl examples we looked at
during Week 6 which also used print("Content-type:
text/html\n\n");
CGI is still used quite a bit in the Web world, but serious
complaints have been made about it.
- Spawning a child process is hard work and costs time and memory.
This problem with speed has prompted many a complaint from producers
of high-traffic Web sites.
- Web servers contain a lot more information than just environment
variables and STDIN. It would be handy
sometimes for Web programs to gain access to these extra tidbits.
- The whole classical programming paradigm has proven cumbersome for
most Web-programming needs. What you're really trying to do is write
a program that will intelligently compose HTML on your behalf. So,
why does it look like computer code? Why can't it look more like
HTML?
Web-Embedded
Programming
More modern ways of programming Web applications have arisen over the
past few years. Their roots lie in Server-parsed HTML - Server
Side Includes (SSIs) (.shtml
- UNIX or .stm - Windows), a
programming option that's been on the scene since almost the beginning,
but was never powerful enough for serious application programming.
The new languages and techniques revolve around embedding
programming code into HTML files. Some popular examples are:
- Active
Server Pages (.asp
files) are used by the Microsoft IIS Webserver. ASP files can be
activated with several different scripting engines, including
VBScript, JavaScript, and PerlScript.
(Code Example) & (Form
Using Get & Form Using Post - Form.asp
- v1 & Form.asp - v2)
NOTE: ASP has been ported to UNIX and Linux using two
different development tracks:
- Commercial (ChiliSoft) - expensive
- Perl Module - free
- Allaire
Cold Fusion (.cfm
files) provide a very handy commercial Web-development environment.
Though it started off only being available on the Windows NT side of
the house, lately it's cropped up on the UNIX and Linux as well.
(Code Example)
- PHP (.php
or .php3 files) like
Active Server Pages except on steroids. PHP incorporates features
from Shell programming, C programming, Perl, and Java. Works on NT,
UNIX, and Linux platforms.
(Code Example - Script
in Action)
|