How reliable is $

From what I've read, it seems that $_SERVER['REQUEST_URI'] won't always return query strings properly, but does anyone have a good sense of what the success rate is? Will it work in the majority of cases for the average client?

What, if anything, would cause REQUEST_URI to not be populated or not include the query string?


You asked:

What, if anything, would cause REQUEST_URI to not be populated?

Answers that I can think of:

  • The web server provides all the $_SERVER values to PHP, so if the server doesn't provide them, then they won't be set. This is highly unlikely with any decent web server, but is possible.

  • If you run a PHP program from the command line, it won't have any $_SERVER values. (in case you're not worried about this, bear in mind that unit tests are typically run from a command line, so it does matter if you're following best practices and writing unit tests)


  • What, if anything, would cause REQUEST_URI to not be populated?

    A Google search seems to indicate this to have been the case with IIS (but what was true then, might not be now):

    https://bugs.launchpad.net/xibo/+bug/654536
    

    (there is an article about a fix for IIS: http://davidwalsh.name/iis-php-server-request_uri )

    as well as other cases in which the "server" was not your standard web server (eg debugging server plugin, etc.).

    It was noticed but considered a bug in less known or old versions of web servers (lighthttpd, iPlanet Web Server 7.0).

    So I believe you can be reasonably sure that the variable is always going to be populated. Of course, it would be wise to prepare a very small test script to run at the customer's site as early as possible in order to be forewarned.

    链接地址: http://www.djcxy.com/p/42264.html

    上一篇: SERVER ['REQUEST

    下一篇: $有多可靠