CGI Notes
CGI Notes
1. Architecture of CGI
2. CGI Environment Variables
All the CGI programs have access to the following environment variables. These
variables play an important role while writing any CGI program.
Sr. No. Variable Name & Description
1 CONTENT_TYPE: The data type of the content. Used when the client is sending
attached content to the server. For example, file upload.
2 CONTENT_LENGTH: The length of the query information. It is available only for
POST requests.
3 HTTP_COOKIE: Returns the set cookies in the form of key & value pair.
7 REMOTE_ADDR: The IP address of the remote host making the request. This is
useful logging or for authentication.
8 REMOTE_HOST: The fully qualified name of the host making the request. If this
information is not available, then REMOTE_ADDR can be used to get IR address.
9 REQUEST_METHOD: The method used to make the request. The most common
methods are GET and POST.
The GET method is the default method to pass information from the browser to the web
server and it produces a long string that appears in your browser's Location:box.
Never use GET method if you have password or other sensitive information to pass to the
server.
The GET method has size limitation: only 1024 characters can be sent in a request string.
The GET method sends information using QUERY_STRING header and will be accessible
in your CGI Program through QUERY_STRING environment variable.
Example:
/cgi-bin/hello_get.py?first_name=TMU&last_name=UP
4. File Upload
To upload a file, the HTML form must have the enctype attribute set to multipart/form-data.
The input tag with the file type creates a "Browse" button.
<html>
<body>
</form>
</body>
</html>