I wanted to know if it is possible to GET and POST on the same php page, for example
I want to send data to:
http://www.example.com/my.php
So first the GET
http://www.example.com/my.php?task=dosomething
and POST some $thexml = XML
to
http://www.example.com/my.php?task=dosomething
and then be able to access both in some code like (example)
// Example Code ============================
if($_GET["task"] == "dosomething"){
$mynewxml = $_POST["$thexml"];
}
//==========================================
Technically no, you cannot
POST
andGET
at the same time. They are two different verbs, and you only get to make one during your request.However, you will find that if you do a
POST
and include parameters in the URL, such asyourscript.php?param1=somevalue¶m2=somevalue
, then both$_GET
and$_POST
will be populated with their respective data.It would be wise to read up on how HTTP actually works. http://www.jmarshall.com/easy/http/
You should consider whether or not this is good system design on your part. A
GET
is supposed to be for requests that don't change data on the server. APOST
can change data. Even though both can be implemented to do either, it is best to follow this common practice. You never know what some proxy or other program up the line will do with it otherwise.This is how I do it....
Yes, my young Padawan. It is as simple as changing the post attribute in a form.
or
And adding a submit button. Upon submitting, you access the HTTP Request Post/GET data stored in their respective variables.
You can't use both methods from the client (two different requests) and see all parameters in the same execution of your PHP script. You need to choose POST or GET.
You can use both GET and POST data coming from the same request, as others signaled.
If you need to collate data from several different request (for any reason) you need to store and manage those intermediate data yourself.
Yes, you can do this by including the
$_GET
parameters as part of the form action:Yes you can. Make sure to use
$_GET
for get and$_POST
. There is also$_REQUEST
which combines the two in one array. Using this is discouraged.