PHP 中的 PATH_INFO 到底是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2261951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly is PATH_INFO in PHP?
提问by user198729
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.
所有外部 URL 看起来都像“module/action?key1=param1”。无法进行定制——但速度很快。区别在于第一个使用 PHP 的 GET,第二个使用 PATH_INFO。
I've seen PATH_INFOseveral times, but still don't know what exactly it is. What does it do?
看了PATH_INFO好几遍,还是不知道具体是什么。它有什么作用?
回答by Andrew Moore
Actually, PATH_INFOis related to the Apache Web Server serving PHP pages and not PHP per se.
实际上,PATH_INFO与提供 PHP 页面的 Apache Web 服务器有关,而不是 PHP 本身。
PATH_INFOis an environment variable set by Apache when the AcceptPathInfodirectiveis 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.
PATH_INFO是当AcceptPathInfo指令打开时由 Apache 设置的环境变量。无论请求是被接受还是被拒绝,它将包含跟随实际文件名或现有目录中不存在的文件的尾随路径名信息。然后将环境变量传递给负责呈现页面的 Apache/CGI 模块。
The variable is accessible in PHP using $_SERVER['PATH_INFO'].
该变量可在 PHP 中使用$_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/moreand /test/nothere.html/moreboth collect /moreas PATH_INFO.
例如,假设该位置/test/指向一个仅包含单个文件的目录here.html。然后请求/test/here.html/more和/test/nothere.html/more都收集/more为PATH_INFO。
回答by SimonSimCity
As the variable PATH_INFO is part of the definition for CGI you should also take a look in there ;)
由于变量 PATH_INFO 是 CGI 定义的一部分,因此您还应该查看其中的内容;)

