]> granicus.if.org Git - apache/blob - docs/manual/cgi_path.html.en
ie40 screws up vary
[apache] / docs / manual / cgi_path.html.en
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML><HEAD>
3 <TITLE>PATH_INFO Changes in the CGI Environment</TITLE>
4 </HEAD>
5
6 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
7 <BODY
8  BGCOLOR="#FFFFFF"
9  TEXT="#000000"
10  LINK="#0000FF"
11  VLINK="#000080"
12  ALINK="#FF0000"
13 >
14 <!--#include virtual="header.html" -->
15 <H1 ALIGN="CENTER">PATH_INFO Changes in the CGI Environment</H1>
16
17 <HR>
18
19 <H2><A NAME="over">Overview</A></H2>
20
21 <P>As implemented in Apache 1.1.1 and earlier versions, the method
22 Apache used to create PATH_INFO in the CGI environment was
23 counterintuitive, and could result in crashes in certain cases. In
24 Apache 1.2 and beyond, this behavior has changed. Although this
25 results in some compatibility problems with certain legacy CGI
26 applications, the Apache 1.2 behavior is still compatible with the
27 CGI/1.1 specification, and CGI scripts can be easily modified (<A
28 HREF="#compat">see below</A>).
29
30 <H2><A NAME="prob">The Problem</A></H2>
31
32 <P>Apache 1.1.1 and earlier implemented the PATH_INFO and SCRIPT_NAME
33 environment variables by looking at the filename, not the URL. While
34 this resulted in the correct values in many cases, when the filesystem
35 path was overloaded to contain path information, it could result in
36 errant behavior. For example, if the following appeared in a config
37 file:
38 <PRE>
39      Alias /cgi-ralph /usr/local/httpd/cgi-bin/user.cgi/ralph
40 </PRE>
41 <P>In this case, <CODE>user.cgi</CODE> is the CGI script, the "/ralph"
42 is information to be passed onto the CGI. If this configuration was in
43 place, and a request came for "<CODE>/cgi-ralph/script/</CODE>", the
44 code would set PATH_INFO to "<CODE>/ralph/script</CODE>", and
45 SCRIPT_NAME to "<CODE>/cgi-</CODE>". Obviously, the latter is
46 incorrect. In certain cases, this could even cause the server to
47 crash.</P>
48
49 <H2><A NAME="solution">The Solution</A></H2>
50
51 <P>Apache 1.2 and later now determine SCRIPT_NAME and PATH_INFO by
52 looking directly at the URL, and determining how much of the URL is
53 client-modifiable, and setting PATH_INFO to it. To use the above
54 example, PATH_INFO would be set to "<CODE>/script</CODE>", and
55 SCRIPT_NAME to "<CODE>/cgi-ralph</CODE>". This makes sense and results
56 in no server behavior problems. It also permits the script to be
57 guaranteed that
58 "<CODE>http://$SERVER_NAME:$SERVER_PORT$SCRIPT_NAME$PATH_INFO</CODE>"
59 will always be an accessible URL that points to the current script,
60 something which was not necessarily true with previous versions of
61 Apache.
62
63 <P>However, the "<CODE>/ralph</CODE>"
64 information from the <CODE>Alias</CODE> directive is lost. This is
65 unfortunate, but we feel that using the filesystem to pass along this
66 sort of information is not a recommended method, and a script making
67 use of it "deserves" not to work. Apache 1.2b3 and later, however, do
68 provide <A HREF="#compat">a workaround.</A>
69
70 <H2><A NAME="compat">Compatibility with Previous Servers</A></H2>
71
72 <P>It may be necessary for a script that was designed for earlier
73 versions of Apache or other servers to need the information that the
74 old PATH_INFO variable provided. For this purpose, Apache 1.2 (1.2b3
75 and later) sets an additional variable, FILEPATH_INFO. This
76 environment variable contains the value that PATH_INFO would have had
77 with Apache 1.1.1.</P>
78
79 <P>A script that wishes to work with both Apache 1.2 and earlier
80 versions can simply test for the existence of FILEPATH_INFO, and use
81 it if available. Otherwise, it can use PATH_INFO. For example, in
82 Perl, one might use:
83 <PRE>
84     $path_info = $ENV{'FILEPATH_INFO'} || $ENV{'PATH_INFO'};
85 </PRE>
86
87 <P>By doing this, a script can work with all servers supporting the
88 CGI/1.1 specification, including all versions of Apache.</P>
89
90 <!--#include virtual="footer.html" -->
91 </BODY>
92 </HTML>
93