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

37,758

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

Share:
37,758

Related videos on Youtube

zhuanzhou
Author by

zhuanzhou

QQ:285967378

Updated on December 01, 2020

Comments

  • zhuanzhou
    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 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.

  • Phil
    Phil about 13 years
    I think it's meant to be ORIG_PATH_INFO. It seems some server configurations create this instead of PATH_INFO.
  • Phil
    Phil about 13 years
    PATH_INFO is used in both Symfony and ZF so I wouldn't call it "rarely used"
  • mario
    mario about 13 years
    Then 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
    Josh Davenport-Smith over 7 years
    Just to add to this as I needed to use PATH_INFO and got a bit misled by PATH_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
    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
    Kamafeather over 2 years
    ORIG_PATH_INFO is also used in Agavi (AgaviWebRequest.class.php).
  • Beda Schmid
    Beda Schmid about 2 years
    php.net/manual/en/reserved.variables.server.php: ORIG_PATH_INFO: > Original version of 'PATH_INFO' before processed by PHP.

Related