views:

36

answers:

3

I want to be able to return all of the parameters that are being passed into a specific page using PHP.

$_SERVER['QUERY_STRING'];

Seems to perform this task adequately, however I have heard many warn against the use of $_SERVER variables due to their sometimes inconsistent nature. So I was wondering if there are any best practice guidelines on creating a string consisting of everything after the ? of a URL.

+1  A: 

I don't know of any generic way to access the QUERY_STRING except that.

My solution to this is to translate all needed $_SERVER/$_ENV variables into normal ones in a separate file kept in the configuration directory. That way, they are easy to change when needed.

Anyway, "inconsistent nature" refers to the fact that they may vary on different server setups, but not within the same environment.

Pekka
+1  A: 

You can try http_build_query($_GET) :)

Although, if your query is "a[]=1" then it will generate "a[0]=1". Most times it doesn't matter.

hegemon
Ah, the Joys of PHP5. Didn't know this one. +1
Pekka
A: 

Some $_SERVER (environment) variables are inconsistent or server-dependent. QUERY_STRING isn't though, it's a basic and well-supported part of the CGI standard from which PHP was built. It's solid.

bobince