40

all external URLs look like 'module/action?key1=param1'. No customization possible--but it's fast. The difference is that the first uses PHP's GET, and the second uses PATH_INFO.

I've seen PATH_INFO several times, but still don't know what exactly it is. What does it do?

David Refoua
  • 3,476
  • 3
  • 31
  • 55
user198729
  • 61,774
  • 108
  • 250
  • 348

2 Answers2

50

Actually, PATH_INFO is related to the Apache Web Server serving PHP pages and not PHP per se.

PATH_INFO is an environment variable set by Apache when the AcceptPathInfo directive is turned on. It will contain trailing pathname information that follows an actual filename or non-existent file in an existing directory, whether the request is accepted or rejected. Environment variables are then passed on to the Apache/CGI module in charge of rendering the page.

The variable is accessible in PHP using $_SERVER['PATH_INFO'].

For example, assume the location /test/ points to a directory that contains only the single file here.html. Then requests for /test/here.html/more and /test/nothere.html/more both collect /more as PATH_INFO.

Apache Core Documentation: AcceptPathInfo Directive

cxw
  • 16,685
  • 2
  • 45
  • 81
Andrew Moore
  • 93,497
  • 30
  • 163
  • 175
  • 20
    After reading your answer, one could infer it's a bad practice to rely on PATH_INFO and it isn't. PATH_INFO is part of of the definition for CGI (as SimonSinCity pointed). It is supported by most web server, not just Apache. – Francisco R Aug 09 '14 at 09:29
26

As the variable PATH_INFO is part of the definition for CGI you should also take a look in there ;)

The PATH_INFO variable specifies a path to be interpreted by the CGI script. It identifies the resource or sub-resource to be returned by the CGI script, and is derived from the portion of the URI path hierarchy following the part that identifies the script itself. Unlike a URI path, the PATH_INFO is not URL-encoded, and cannot contain path-segment parameters. A PATH_INFO of "/" represents a single void path segment.

 PATH_INFO = "" | ( "/" path )
 path      = lsegment *( "/" lsegment )
 lsegment  = *lchar
 lchar     = <any TEXT or CTL except "/">

https://www.rfc-editor.org/rfc/rfc3875#section-4.1.5

Community
  • 1
  • 1
SimonSimCity
  • 6,415
  • 3
  • 39
  • 52