![]() |
CGI Environment Variables![]() ![]() ![]() ![]() ![]()
Regardless of whether any form data is being passed to the CGI program or not, every CGI application receives information about both the browser and the server through environment variables.
General Variables This section defines the most general of the environment variables, those that every CGI script will need to be able to read input from the server. Gateway_interface GATEWAY INTE R FACE describes the version of the CGI interface being used. The current version of the interface is 1.1, so the value of this variable is almost always CGI/1.1. Server_protocol SERVER PROTOCOL describes the version of the HTTP protocol. Most servers understand version 1.0, hence this value is usually HTTP/1.0. Request_method REQUEST METHOD is either equal to GET or POST, depending on the method used to send the data to the CGI program. Variable Storing Input This section defines those variables that can contain the actual input data being passed from the server to the CGI program. Pth_info The user can specify a path value when the user accesses a CGI program by appending a slash (/) followed by the path information. Path_translated PATH TRANSLATED is the equivalent value of PATH INFO relative to your file system. If your document root is /usr/local/etc/httpd/htdocs Query_string This variable contains input data if the server is sending data using the GET method. It will always contain the value of the string following the URL and separating question mark, regardless of how information is being passed to the CGI program. For example, if you access the following: http://myserver.org/cgi bin/mai1.cgi?static directly from the command line, the value of QUERY STRING is static even though the information is being passed directly and is not a series of name/ value pairs. Content_type CONTENT TYPE contains a MIME type that describes how the data is being encoded. By default, CONTENT TYPE will be application/x www form urlencoded. Note that this is the same MIME type normally specified in the ENCTYPE parameter of the <form> tag. Content_Length CONTENT LENGTH stores the length of the input being passed to the CGI program. This variable is defined only when the server is using the POST method. For example, if the following is your input string, then CONTENT LENGTH is 24 because there are 24 characters in this string: name=sujea n°ree =music Server Information This section defines environment variables that deal with information about the server. Server_Software SERVER SOFTWARE is the name and version of the server you are using. SERVER NAME is the name of the machine running your server. This is the e mail address of the administrator of your Web server. Not all servers define this variable. This is the port on which your server is running. The default port for Web servers is 80. This is the name of the CGI program. You can use SCRIPT NAME to write a CGI program that reacts differently depending on the name used to call it. For example, you could write a CGI program that would display a picture of a cat if SCRIPT NAME was cat or a picture of a dog if SCRIPT NAME was dog. The CGI program would be the same, but you would save it twice: one time as cat and the other as dog. This is the value of the document root on your server. For example, if your document root is /usr/local/etc/httpd/, the value of DOCUMENT ROOT is /usr/ local/etc/httpd/ This section defines environment variables that deal with information about the client (browser). This is the name of the machine currently requesting or passing information to your CGI program. For example, if someone at toyotomi. student. harvard.edu is browsing your Web site, the value of REMOTE HOST passed to the CGI program is toyotomi.student.harvard.edu. This is the IP address of the client machine. For example, if someone at IP address 140.247.187.95 is currently browsing your Web site, the value of REMOTE ADDR is 140.247.187.95. Both REMOTE HOST and REMOTE ADDR can be useful for writing programs that will respond differently depending on the point from which you are browsing the Web site. REMOTE ADDR tends to be a more reliable value, because not all machines on a TCP/IP network like the Internet have host names, but all of them will have an IP address. Remote User
If you have entered a valid username to browse an access restricted area on the server, your username is stored in REMOTE USER. By default, REMOTE USES empty. If you access a page with access restrictions, the server first check, REMOTE USER to see if you have authenticated yourself already. If not, responds with a status code of 401. When the client receives this status code, it prompts you for the appropriate information, usually a username and password.
Remote_group Some servers have group authentication as well as user authentication. Wit' group authentication, you usually enter your username, and the server looks see whether you belong to the appropriate group. If you do, it stores that value REMOTE GROUP and enables you to access the appropriate documents. Net servers support this form of authentication. Auth_type AUTH TYPE defines the authorization scheme being used, if any. The most common authentication scheme is Basic. Remote_ident Although the server and CGI program can determine the name of the cited, machine and address currently connected, it normally cannot determine the use, on the client machine accessing your pages. A network protocol known as the IDENT protocol enables querying servers to determine which users from which machines are connecting to your server. HTTP Variables Many browsers pass additional information about their capabilities to the server which in turn passes this information to the CGI program in the form of environment variables, These variables are prefixed with HTTP HTTP_ACCEPT
HTTP_ACCEPT contains a list of MIME types that the browser is capable of interpreting itself.
Each MIME type is separated by a comma. For example, a graphical browser that can display both GIF and JPEG images might list the following. image/gif image/jpeg in HTTP ACCEPT
HTTP_ACCEPT
HTTP_USER_AGENT This variable stores the browser name, version, and usually its platform. Normally, the format of HTTP_USER_AGENT is Browser/Version (Operating System) HTTP_REFERER HTTP_REFERER stores the URL of the previous page that referred you to the current URL. CGI Program to print the environment variables
In order to write a CGI application that displays the environment variables, you have to know how to do two things:
print "Content-type:text/html\n\n";
|
|
CGI
Advantages of CGI
How CGI Works
Compiled Versus Interpreted
Input to CGI
CGI Introduction Program
HTML Forms
Accepting Input from the Browser
CGI Environment Variables
Get Versus Post Method
Get Method
Post Method
Sample <FORM> Based CGI Program
Complete Example for <FORM>
Output from CGI
Header and Body:Anatomy of Server Response
HTTP Headers
Carriage Returns and Newlines
Formatting Output CGI Common MIME TypesLocation Header Useful HTTP Stautus Codes Other Headers Dynamic Pages Sending Images Displaying the Current Date Feedback Form Program Server Side Includes Server Side Include Environment Variables Displaying the Date with Date Counter Example of SSI Counting the Number of Accesses Better Approach Towards CGI Program Client Versus Server Accessing a HTML Document Submitting a Form Accessing a CGI Program Databases ODBC Creating a DSN Win32::ODBC Module Creating a Table Inserting Data into a Table Deleting Data from a Table
Updating Data in a Table
Selecting Data from a Table Operating Systems Security Securing Your Web Server Writing Secure CGI ProgramWeb DesignDomain Names Home
FAQ
My Account
IP Address
SSL Certificates DNSWeb Hosting Web Server Cheap Web Design Dedicated web hosting Managed web hostingE Commerce Principles of E-Commerce E-Banking Electronic Payment System E-Security Credit Cards Smart Cards
The Mailbox POP Server SMTP Server IMAP Protocol |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |