开发者

Is there a PHP variable which includes the merge of $_GET and $_POST?

$_REQUEST includes cookies which I do NOT want in my 开发者_开发知识库form posts.


The php.ini setting responsible for what is in $_REQUEST is variables_order

Default: variables_order "EGPCS"

Change that in your php.ini to:

GP

for it to include only $_GET and $_POST

Maybe you don't want to do that

Usually in a web application you use $_GET values to select what to show and $_POST values to transmit what there is to change in a webpage (or user actions that change state in general). Generally it's not advisable to mix those :)

Also that answers explains it quite nice: When and why should $_REQUEST be used instead of $_GET / $_POST / $_COOKIE?

Or maybe read this: What's wrong with using $_REQUEST[]?

Also thanks for the comment mario :)


$new_array = array_merge($_GET, $_POST);


You can change what $_REQUEST holds by looking into the php.ini setting variables_order. Start here.


You should not use $_REQUEST for exactly that reason. Access $_GET, $_POST and friends for their dedicated purposes instead of using $_REQUEST.


You can simply use:

$_REQUEST = array_merge($_GET, $_POST);

Which has the benefit of explicitly listing the order you'd like so you don't override something you didn't expect because the REQUEST order was off.


I would be explicit.

If a GET/POST merge is required in some context, then apply it then -- but I would avoid a blatant clobber. This merge can be easily done per-item and hidden behind a nice, tidy and default-applying wrapper -- perhaps even with a sanitizing/coversion layer right then and there.

No magic required. Happy coding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜