开发者

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

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

When I run print_r($_SERVER), PATH_INFO and ORIG_PATH_INFO are not present in the array. Why not? How can I enable them?

I have read the PHP manual开发者_如何转开发 on them, but still don’t understand them.


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

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

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

The PORIG_ prefix is somewhat uncommon. PATH_INFO is 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.)

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


try this :

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


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.

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.


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

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

The PHP manual says that ORIG_PATH_INFO is:

Original version of 'PATH_INFO' before processed by PHP.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜