When can there be data in both $ _GET and $ _POST

Is it possible to get data in both $ _GET and $ _POST? And how does this relate to what's in $ _REQUEST?

+7
php
source share
4 answers

Yes it is possible. Consider this form:

<form action="foobar.php?a=123&b=456" method="post"> <input type="text" name="a" value="llama"> <input type="text" name="b" value="duck"> <input type="submit" name="go" value="Submit me!"> </form> 

When submitting this form, $_GET["a"] == "123" , $_GET["b"] == "456" , $_POST["a"] == "llama" , $_POST["b"] == "duck" and $_POST["go"] == "Submit me!" .

How this relates to $_REQUEST superglobal depends on the value of request_order (or older variables_order ) PHP configuration documentation php.ini is explained .

+16
source share

In both cases, there may be data ... Consider the following (very simple) page:

 <body> <form method="post" action="params.php?myparam=myval"> <input type="text" name="param1"></input> <input type="submit" name="submit" value="submit" /> </form> </body> 

Note that the action form contains the query string, and the method contains post . $_GET contains the query string parameters, $_POST contains the form parameters, and $_REQUEST contains the combined parameters from both arrays:

 array(3) { ["myparam"]=> string(1) "myval" ["param1"]=> string(0) "" ["submit"]=> string(6) "submit" } 

Check request_order to control the processing of super-global in $_REQUEST .

+2
source share

It is possible. The request_order directive or (if this is not set) variables_order determines that it will take precedence in $_REQUEST when the key is set in both.

+1
source share

This is possible in PHP because, despite their names, $ _GET and $ _POST do not really need GET or POST.

  • $ _ GET contains a validation request processed as form variables.
  • $ _ POST contains the request body, parsed as form variables.

It doesn't matter what the actual request method is - it could be PUT, and these superglobals will still be filled.

0
source share

All Articles