Accessing Raw XML Posted to a Script

This is post is now quite old and the the information it contains may be out of date or innacurate.

If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub

If you have a script that is receiving posted XML for whatever reason and are trying to access this XML without any filtering, escaping etc then this is the solution you are looking for.

Instead of trying to access via $_POST etc, you can simply call the following:

$xml = file_get_contents('php://input');

This will then allow you to load it into Simple XML for example for further processing

$sx = simplexml_load_string($xml);
if($sx){
   ....
}

Tags: postserverxmlraw