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

前端 未结 4 967
闹比i
闹比i 2020-12-16 21:32

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

When I run print_r($_SERVE

相关标签:
4条回答
  • 2020-12-16 22:09

    try this :

    $path_info = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (!empty($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : '');
    
    0 讨论(0)
  • 2020-12-16 22:16

    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 讨论(0)
  • 2020-12-16 22:20

    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.

    0 讨论(0)
  • 2020-12-16 22:29

    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

    0 讨论(0)
提交回复
热议问题