Formatting Output in CGI

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

In the preceding example, the server retrieved the HTML file and added the entire HTTP header itself. Web servers work almost exactly the same with CGI programs, except the server will provide only some of the headers; it expects the CGI program to provide the other important headers.

At the minimum, CGI programs need to return only one header. either a ContentType or Location header. The former is the more common of the two. As discussed earlier, Content Type tells the browser what sort of information to expect. Location offers an alternative location for certain data; this is useful for redirection and other types of requests. CGI programs can optionally send other HTTP headers, as well.

The Web browser needs to know what kind of information it's receiving so it knows how to properly display it. If it receives a GIF image, it needs to either display it inline or open an external application that will display it. If it receives an HTML file, it needs to interpret and render the HTML.

The server uses the MIME format to identify the file type to the browser. MIME was originally designed to extend the Internet mail protocol to use multimedia rather than just plain text. The MIME format as it applies to multimedia mail is not important for CGI programming. What you should be concerned with here is the MIME Content Type header. Data format content types are specified as follows:

type/subtype

The "type" specifies the general type of data. There are seven types:

Text
Image
Audio
Video
Application
Multipart and
Message

Text, image, audio, and video are self explanatory. The application type specificapplication specific or binary data. Multipart designates a document with several different content types embedded within one document', this type has some special uses for CGI programming, such as server side push. The subtype give, more exact information about the specific type. Text files can be plain text, rich text format (RTF), or HTML. Images can be GIF, JPEG, or countless other formats.



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.