Common Error Messages

If you get a server-generated error page when trying to access your CGI, there is usually a string which explains why the script generated an error. The most common are:

Premature end of script headers

This is probably the most common error which is seen, both during development and in production. To better explain this error, it helps to have some background on what the web server expects a CGI to return.

The basic stucture of a CGI's response is:

Content-type: mime-type
extraheader: extravalue


For most applications, the mime-type is set to text/html, since HTML is the most common content returned to the browser. The CGI can add as many other headers as it needs, or just specify the content type. Following the last header is a blank line, and the content follows that blank line.

Apache, which is the web server used on, will generate an error of Premature end of script headers if it does not see the blank line. Some cases which will create this error are:

malformed header from script. Bad header=text

Looking again at the format of CGI output, we can see that this error message will occur if the script displayed content and no headers; that content should show up as text in the error.

Another possible cause for this error message is if no blank line was output after the headers and before the content.

file permissions deny server execution

As can be expected, this error means you should check that your CGI has the execute bit set.

Document contains no data

Unlike the other errors, this is a message displayed by some browsers as a dialog box. Since the server didn't display an error about the headers ending prematurely, that means that the headers were fine. However, if the script exits after the headers and blank line, but before any content, then the browser has no content to display, and therefore will show this message.

Directory indexing forbidden by rule

You will see this error if you are trying to view a directory which has no index.html or index.cgi file.