php $_SERVER['PATH_INFO'] 和 $_SERVER['ORIG_PATH_INFO'] 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5629683/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:01:57  来源:igfitidea点击:

What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']?

phpapache

提问by zhuanzhou

What's the difference between $_SERVER['PATH_INFO']and $_SERVER['ORIG_PATH_INFO']? How do I use them?

$_SERVER['PATH_INFO']和 和有$_SERVER['ORIG_PATH_INFO']什么区别?我如何使用它们?

When I run print_r($_SERVER), PATH_INFOand ORIG_PATH_INFOare not present in the array. Why not? How can I enable them?

当我运行时print_r($_SERVER)PATH_INFO并且ORIG_PATH_INFO不存在于数组中。为什么不?我怎样才能启用它们?

I have read the PHP manual on them, but still don't understand them.

我已经阅读了关于它们的 PHP 手册,但仍然不理解它们。

回答by mario

The PATH_INFOvariable is only present if you invoke a PHP script like this:

PATH_INFO变量仅在您像这样调用 PHP 脚本时才存在:

http://www.example.com/phpinfo.php/HELLO_THERE

It's only the /HELLO_THEREpart after the .phpscript. If you don't invoke the URL like that, there won't be a $_SERVER["PATH_INFO"]environment variable.

这只是脚本/HELLO_THERE之后的部分.php。如果你不这样调用 URL,就不会有$_SERVER["PATH_INFO"]环境变量。

The PORIG_prefix is somewhat uncommon. PATH_INFOis a standard CGI-environment variable, and should never be prefixed. Where did you read that? (There were some issues around PHP3/PHP4 if you invoked the PHP interpreter via cgi-bin/ - but hardly anyone has such setups today.)

PORIG_前缀是有点少见。PATH_INFO是一个标准的 CGI 环境变量,永远不应该加前缀。你从哪里读到的?(如果您通过 cgi-bin/ 调用 PHP 解释器,PHP3/PHP4 会出现一些问题 - 但今天几乎没有人有这样的设置。)

For reference: http://www.ietf.org/rfc/rfc3875

供参考:http: //www.ietf.org/rfc/rfc3875

回答by dhamaso

try this :

尝试这个 :

$path_info = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '');

回答by Wige

PATH_INFO and ORIG_PATH_INFO are rarely used. These refer to anything in the request path (the part of the URL from the first / on) that comes after the name of the file, and the query string. Generally, you won't have a PATH_INFO in a URL.

PATH_INFO 和 ORIG_PATH_INFO 很少使用。这些是指请求路径中的任何内容(从第一个 / 开始的 URL 部分)中出现在文件名和查询字符串之后的任何内容。通常,URL 中不会包含 PATH_INFO。

I am guessing you mean ORIG_PATH_INFO and not PORIG_PATH_INFO. The path info may be manipulated by things like mod_rewrite and PHP scripts themselves. ORIG_PATH_INFO is the PATH_INFO as it was in the original request, before any rewriting or other manipulation was done to the string.

我猜你的意思是 ORIG_PATH_INFO 而不是 PORIG_PATH_INFO。路径信息可能会被诸如 mod_rewrite 和 PHP 脚本本身之类的东西操纵。ORIG_PATH_INFO 是原始请求中的 PATH_INFO,在对字符串进行任何重写或其他操作之前。

回答by Alan

Prior to 5.2.4, PATH_INFOwas apparently broken (not set) in the default configuration. Perhaps that's it.

在 5.2.4 之前,PATH_INFO在默认配置中显然已损坏(未设置)。也许就是这样。

https://bugs.php.net/bug.php?id=31892

https://bugs.php.net/bug.php?id=31892

The PHP manual says that ORIG_PATH_INFOis:

PHP手册说的ORIG_PATH_INFO是:

Original version of 'PATH_INFO' before processed by PHP.

由 PHP 处理之前的“PATH_INFO”的原始版本。

Reference:
http://php.net/manual/en/reserved.variables.server.php

参考:http:
//php.net/manual/en/reserved.variables.server.php