Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How reliable is $_SERVER['REQUEST_URI'] at capturing query strings?

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?

like image 871
David Jones Avatar asked Oct 07 '12 21:10

David Jones


2 Answers

You asked:

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

Answers that I can think of:

  1. 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.

  2. 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)

like image 131
Spudley Avatar answered Oct 20 '22 03:10

Spudley


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 (e.g. 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.

like image 45
LSerni Avatar answered Oct 20 '22 03:10

LSerni