Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

like image 357
Don Avatar asked Nov 15 '09 06:11

Don


People also ask

Can I use GET and POST at the same time?

With Ajax you can send data to a PHP script via GET and POST in the same request. The process is similar to sending data through the POST, it's actually the same, being only applied a "trick".

What is the purpose $_ GET and $_ POST variable?

$_GET, and $_POST are array variables of PHP which are used to read submitted data by HTML form using the get and post method accordingly.

What's the difference between $_ GET and $_ POST?

Difference is: $_GET retrieves variables from the querystring, or your URL.> $_POST retrieves variables from a POST method, such as (generally) forms.

Can we use $_ GET and $_ POST interchangeably in PHP?

In some applications, the HTTP methods GET and POST can be used interchangeably. For example, the application may expect a POST request, and the frontend will also send the data in a POST request, but if the request is tampered with, the data will also be accepted in a GET request.


1 Answers

Yes, it's possible. Consider a form like this:

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

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

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

like image 169
bcat Avatar answered Oct 08 '22 06:10

bcat