We have already mentioned that CGI scripts must adhere to standard input and output mechanism (the Interface between browser and server).
For the moment we will not worry about input to a CGI script.
However a CGI script is programmed it MUST send information back in the following format:
CGI Output Header
A browser can accept input in a variety of forms.
Depending on the specified form it will call different mechanisms to display the data.
The output header of a CGI script must specify an output type to tell the server and eventually browser how to proceed with the rest of the CGI output.
There are 3 forms of Header Type:
Content-Type is the most popular type. We now consider this further. We will meet the other types later.
NOTE: Between the Header and Data there MUST be a blank line.
Content-Types
The following are common formats/content-types (there are others - see later):
Format
Content-Type
HTML
text/html
Text
text/plain
Gif
image/gif
JPEG
image/jpeg
Postscript
application/
postscript
MPEG
video/mpeg
To declare the Content-Type your CGI script must output:
Content-Type: content-type specification
Typically the Content-Type will be declared to produce HTML.
So the first line of our CGI script will look this:
Content-Type: text/html
CGI Output Data
Depending on the Content-Type defined the data that follows the header declaration will vary.
If it HTML that follows then the CGI script must output standard HTML syntax.
Thus to produce a Web page that looks sends a simple line of text "Hello World!" to a browser a CGI script must output:
Content-Type: text/html
<html>
<head>
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
Now let us see how we write and display in a Browser this CGI script in Perl