In this section, we will outline several
ways to use CGI scripts to push data to a client such as when you
want to animate text. Specifically, we will discuss nph (non-parsed
header) scripts.
Surely, newer technologies, such as Java, or
plug-ins, such as Shockwave, are better suited for complex animation.
However, the ability to use NPH scripts in
creative ways is an important part of any CGI programmer's box of
tools. NPH scripts add another dimension to multimedia and can make
your site more diverse. They can also be used when the big guns of
Java or Shockwave are not appropriate.
Nonparsed header scripts are used when we
want to bypass the server.
Usually, when we use the line
print "Content-type: text/plain\n\n";
we count on the fact that the server that
executes the script will fill in the rest of the HTTP protocol lines,
such as the "200 OK" status codes, the date and time, and other
information defined in the protocol.
With NPH scripts, we must generate those HTTP
protocol messages internally, bypassing server parsing. In other
words, we output directly to the browser without Web server
intervention.
Most of the information that you might pass
to the browser is optional. However, you should at least return the
MIME content type of the data, the HTTP protocol revision, the status
of the program, and the server name and version.
By bypassing the server, you can communicate
directly with the browser. As long as the browser listens, you can
continue to feed it more information. In this way, you can use cell
animation to create an animated series of text or images.
However, the use of NPH scripts requires that
all scripts begin with the characters nph-. This is the convention
used by servers to recognize an NPH script. If you rename the script,
the server will not know to treat it as an NPH script and instead will
run it as a normal script.
On the other hand, you may want to include
HTML or images in your animation. In this case, you must specify a
content type and a boundary: