Log in

View Full Version : XML and POST from external server



cleaner
04-12-2010, 04:02 PM
hi,

I have a script that retrieves XML via POST which is working fine:
if (isset($_POST) && $_POST != null) {
$string = $_POST["thexml"];
}

<html>
<body>
<form action="test.php" enctype="text/xml" method="POST">
<textarea name="thexml" id="thexml" rows="5" cols="60">
<xml>this works</xml>
</textarea>
<input type="submit">
</form>

However, external XML POST's may be sent to me, and I don't know what the variable name is for $_POST["thexml"] as they could be using $_POST["data"] or something else.

How can I retrieve the posted information without knowing the name of the field they used to post the data? Is a field name always used?

Thanks for your help.

bluewalrus
04-12-2010, 06:50 PM
The form name will always be "thexml" in your example, not sure what you mean.

traq
04-12-2010, 07:14 PM
However, external XML POST's may be sent to me...

If by that you mean that people may send you POST data from their own forms/websites, I would strongly recommend against it. You should always force users to submit data to you via your own forms, in fact, you should check to verify that that is the case.

cleaner
04-13-2010, 10:00 AM
Let's rephrase this question:
Basically I have an external system posting a raw output stream to my script (after authentication of course). How can I catch everything that is posted and dump it into text files?

$f = fopen ($file, 'w');
foreach($_POST as $key => $value){
fputs ($f, $value);
}
fclose ($f);

traq
04-13-2010, 02:29 PM
As long as this
<textarea name="thexml" id="thexml" rows="5" cols="60"> is always named "thexml", you can always access the data using $_POST['thexml'] . If it varies, you'd need some way of predicting it.