How Web Pages Run CGI Programs
There are several ways a Web page can run a CGI program:
URLs that Run CGI Programs
For each method of running a CGI program described in the previous section, the browser software sends a URL to the server. (In addition, the HTTP header sent with the URL includes some environment variables, which are described on page 108.)
Generally the URL to run a CGI program can have these parts:
CGI path[/extra path information ][?query string]
- The CGI path is the location of the CGI program to run. The path can be a relative or absolute reference to the program file.
- The optional extra path information can be included in the URL to provide either a directory location the CGI program should use or some extra information for the CGI program. The path is relative to the root directory for Web pages. The extra path information is available to the CGI program in the PATH_INFO environment variable.
- The optional query string is preceded by a question mark (?) and contains either a single variable or a set of field names and variables for the CGI program to use. The query string is available to the CGI program in either the QUERY_STRING environment variable or the standard input location (if the form method is POST).
- For example, the query string from a form with 3 fields could be:
Field1=Value1&Field2=Value2&Field3=Value3
- Spaces in the query string are replaced with plus signs (+). Any special characters (such as ?, =, &, +) are replaced with %xx, where xx is the hexadecimal value for that character. (See page 111 for more on how the query string is encoded.)
Here are some examples of URLs that could run a CGI program:
http://www.mysite.com/cgi-bin/gettime
- This URL runs the
gettime
program, which could return a page with the current time. There are no variables, so you might use this as a direct link.
http://www.mysite.com/cgi-bin/listdir/misc/mydir
- This URL runs the
listdir
program and passes it /misc/mydir
as extra path information. This might be a direct link in a page.
http://www.mysite.com/cgi-bin/search?navigate
- This URL runs the
search
program and passes it the word "navigate" as input. This URL doesn't include any field names, so it might be passed by pages with an <ISINDEX> tag.
http://www.webcrawler.com/cgi-bin/WebQuery?searchText=word
- This is a real URL that runs the WebCrawler search program and passes a value for the searchText field of "word". Normally, CGI programs that accept field values like these are run from a form.
- If your programs are not executed, make sure the program file allows read and execute access.