What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']?
Solution 1
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
Solution 2
try this :
$path_info = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '');
Solution 3
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.
Solution 4
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
Related videos on Youtube
Comments
-
zhuanzhou over 3 years
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
andORIG_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.
-
Phil about 13 yearsI think it's meant to be
ORIG_PATH_INFO
. It seems some server configurations create this instead ofPATH_INFO
. -
Phil about 13 years
PATH_INFO
is used in both Symfony and ZF so I wouldn't call it "rarely used" -
mario about 13 yearsThen it's pretty certainly a CGI handler setup. PHP would use the PATH_INFO over SCRIPT_FILENAME in some settings, so the server is likely configured to use an alternative name for path_info.
-
Josh Davenport-Smith over 7 yearsJust to add to this as I needed to use
PATH_INFO
and got a bit misled byPATH_INFO
apparently not being used that much. Based on WordPress using this internally: github.com/WordPress/WordPress/blob/4.4.4/wp-includes/…. It's fair to say it's used an awful lot so use it if you need to! -
MrWhite over 7 years"...that comes after the name of the file, and the query string." - Note that PATH_INFO comes before the query string, not after it.
-
Kamafeather over 2 years
ORIG_PATH_INFO
is also used in Agavi (AgaviWebRequest.class.php). -
Beda Schmid about 2 yearsphp.net/manual/en/reserved.variables.server.php:
ORIG_PATH_INFO
: > Original version of 'PATH_INFO' before processed by PHP.