All Collections
Code Samples
Simple HTTP Connector PHP Receiver
Simple HTTP Connector PHP Receiver

A quick snippet to get you started receiving submissions in PHP

Brett Long avatar
Written by Brett Long
Updated over a week ago

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
 ?>

See Example Below:

//

// 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

?> 

Did this answer your question?