I’m trying to pull data from php://input so that I can store the raw data into an XMLElement, so that I can then sort it, and compare the data to a table in one of my databases. I have also tried using $_POST and storing that but the problem that I ran into using $_POST was that I was not getting field headers so I could not store data.
I’m currently using this code to retrieve the raw data from the http POST.
$PostContents = file_get_contents(php://input);
echo $PostContents;
This is the data that is being returned from that code.
xml=%3COPS%3E+%0D%0A%3CAuthentication%3E%3CSecretKey%3Ex44%3C%2FSecretKey%3E+%0D%0A%3C%2FAuthentication%3E+%0D%0A%3CAction%3EUpdate+Person+Status%3C%2FAction%3E+%0D%0A%3CUpdatePersonStatus%3E+%0D%0A%3CPerson%3E+%0D%0A%3CName%3EDavid%3C%2FOrderNumber%3E+%0D%0A%3CAge%3EShipped%3C%2FOrderStatus%3E+%0D%0A%3CAddress%3EThird+Party%3C%2FAddress%3E+%0D%0A%3CPhone%3EUPS+Grd%3C%2FPhone%3E+%0D%0A%3C%2FPerson%3E%0D%0A%3C%2FUpdatePersonStatus%3E+%0D%0A%3C%2FOPS%3E+%0D%0A
Here is what is generating that output.
<html>
<body>
<form action="http://172.16.100.116/php.php" method="post">
<textarea name="xml" rows="20" cols="40"><OPS>
<Authentication><SecretKey>x44</SecretKey> </Authentication>
<OPS>
<Authentication><SecretKey>x44</SecretKey>
</Authentication>
<Action>Update Person Status</Action>
<UpdatePersonStatus>
<Person>
<Name>David</Name>
<Age>21</Age>
<Address>123EasyStreet</Address>
<Phone>6666666666</Phone>
</Person>
</UpdatePersonStatus>
</OPS>
</textarea>
<input type=submit>
</form>
</body>
</html>
(the html file used here is strictly for testing purposes the data that is coming through is within the plus the header xml information.)
So my question is what do I need to do to get the data from (‘php://input’) into a XML so I can sort it’s information?
You should use urldecode and remove the
xml=urldecode($PostContents);This will be the result