eekim.com > Talks > CGI Programming slides (1996)

Output    (01)

You can send whatever data you want to the web browser, but you must first tell the browser the type of information you are sending. Most of the time, you're sending back an HTML page.    (02)

The proper format for sending information back to the browser is to send one or more HTTP headers, a blank line, and then the information. The most important HTTP header is the content type:    (03)

Content-Type: type/subtype    (04)

Type/subtype is the exact same format as MIME. For HTML, the appropriate MIME header is text/html. So if you were going to send an HTML page from your CGI program back to the browser, it would look something like this:    (05)


Content-Type: text/html

<html> <head>
<title>Testing</title>
</head>
<body>
<h1>Hello!</h1>
</body> </html>    (06)

Note the blank line between the header and the HTML page. This is fairly easy to implement in any programming language or even a simple shell script. All it requires is a bunch of print commands.    (07)

As an exercise, you should create a CGI script which simply sends some output to the web browser.    (08)

Dynamic Pages    (09)

Why is this useful? After all, if you just want to send a static page, there is no need to use a CGI script for that; the server already does that quite well.    (010)

With a knowledge of output using CGI, you can create dynamic pages. For example, you could write a counter program that, when run, would read a number from a file, increment it, and send that number back to the browser. Other applications abound.    (011)

Next | Table of Contents | Previous    (012)