Simple HTTP Connector PHP Receiver

Here's a quick snippet to help get you started if you need to receive submissions in PHP:

//
// Device Magic HTTP Connection Receiver Template
//
// This will receive and parse the XML that is POSTed from HTTP connections
// on the Device Magic server.
//
// Use the $answers and $metadata arrays as you require.
//
<?php  
        $raw_body = @file_get_contents('php://input');
        $xml = simplexml_load_string($raw_body);
 
        $metadata = array();
        foreach($xml->attributes() as $attribute)
        {
                $metadata[$attribute->getName()] = '' . $attribute;
        }      
        foreach($xml->attributes('dm', true) as $attribute)
        {
                $metadata[$attribute->getName()] = '' . $attribute;
        }
        // $metadata contains submission details like submission timestamp and submitting user
 
        $answers = array();
        foreach($xml->children() as $container)
        {      
                foreach($container->children() as $element)
                {      
                        $answers[$element->getName()] = '' . $element;
                }      
        }      
        // $answers contains each answer submitted from the mobile device
?>      

(The sample is also attached.)

Mike

Have more questions? Submit a request

Comments

  • Avatar
    Joe

    Do you have an example of what the response that is required would look like in PHP?

Powered by Zendesk