开发者

Is there a better way of recreating $_SERVER['QUERY_STRING']

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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜