php - PHP 中的 PATH_INFO 到底是什么?

标签 php pathinfo

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.

我已经多次看到PATH_INFO,但仍然不知道它到底是什么。它有什么作用?

最佳答案

实际上,PATH_INFO 与提供 PHP 页面的 Apache Web 服务器相关,而不是 PHP 本身。

PATH_INFO 是 Apache 在 AcceptPathInfo directive 时设置的环境变量已开启。它将包含尾随路径名信息,该信息跟在现有目录中的实际文件名或不存在的文件之后,无论请求是被接受还是被拒绝。然后将环境变量传递给负责呈现页面的 Apache/CGI 模块。

可以使用 $_SERVER['PATH_INFO'] 在 PHP 中访问该变量。

例如,假设位置 /test/ 指向一个目录,该目录仅包含单个文件 here.html。然后请求 /test/here.html/more/test/nothere.html/more 都将 /more 收集为 PATH_INFO

Apache Core Documentation: AcceptPathInfo Directive

关于php - PHP 中的 PATH_INFO 到底是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2261951/

相关文章:

php - 使用 codeigniter Json Mysql Ajax Jquery 进行实时搜索

php - 我如何检测 PHP 中的 (float)0 == 0 或 null

php - 如何减少 TTFB(到第一个字节的时间)响应?

php - 像 http ://localhost/index. php/articles/edit/1/my-first-article 这样的 URL 在没有 .htaccess 的情况下如何工作?

php - 如果文件名是 UTF-8,使 PHP pathinfo() 返回正确的文件名

PHP - 无法通过 mysqli_stmt_send_long_data 发送图像

iis - 在 ColdFusion 中使用 cgi.PATH_INFO 在 URL 中使用 unicode 的问题

PHP - 使用 pathinfo 变量使相对路径不起作用

php - 我如何使用 PHP 下载以某种奇怪的方式重定向的 XML 文件?