getMobileDevice
This function is an advanced version of
isMobileDevice. Use this function to determine whether the device is a mobile device and also receive the model and manufacturer of the device.
Function:
getMobileDevice(devKey, headers)
Parameters:
- devKey - used for authentication and to log usage.
- headers - the headers of the device you wish to query.
Returns: (string)
Upon success, XML containing mobile device information
Upon failure, error codes WAPL markup
Example SOAP Request
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:WaplAPI">
- <SOAP-ENV:Body>
- <ns1:getMobileDevice>
- <devKey>Wapple</devKey>
- <deviceHeaders>
- <deviceItem>
- <name>HTTP_HOST</name>
- <value>wapple.net</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_USER_AGENT</name>
- <value>Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95/10.0.018; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_ACCEPT_CHARSET</name>
- <value>utf-8</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_ACCEPT_LANGUAGE</name>
- <value>en; q=1.0, en, *; q=0.5</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_ACCEPT_ENCODING</name>
- <value>deflate,gzip</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_REFERER</name>
- <value>http://www.wapple.net/</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_CACHE_CONTROL</name>
- <value>max-age=259200</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_CONNECTION</name>
- <value>keep-alive</value>
- </deviceItem>
- <deviceItem>
- <name>HTTP_ACCEPT</name>
- <value>application/vnd.phonecom.mmc-xml, application/vnd.wap.wmlc;type=4365, application/vnd.wap.wmlscriptc, application/vnd.wap.xhtml+xml, application/xhtml+xml;profile="http://www.wapforum.org/xhtml", image/bmp, image/gif, image/jpeg, image/png, image/vnd.wap.wbmp, image/x-up-wpng, multipart/mixed, multipart/related, text/html, text/plain, text/vnd.wap.wml;type=4365, audio/midi, audio/qcelp, audio/vnd.qcelp, application/x-pmd, audio/mid, audio/x-midi, audio/x-mid, audio/mp4, audio/mp3, audio/mpeg4, video/mpeg4, video/mp4, application/vnd.oma.dd+xml, application/vnd.oma.drm.message</value>
- </deviceItem>
- </deviceHeaders>
- </ns1:getMobileDevice>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
Example SOAP Response
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:WaplAPI">
- <SOAP-ENV:Body>
- <ns1:getMobileDeviceResponse>
- <wapple_response>
- <mobile_device>1</mobile_device>
- <manufacturer>Nokia</manufacturer>
- <model>N95-1</model>
- </wapple_response>
- </ns1:getMobileDeviceResponse>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
PHP Example
Nb. The example below uses the native PHP soap extension in PHP. The code is for demonstration purposes only and should be modified for use in a production environment.
- <?php
- try {
- $sClient = @new SoapClient('http://webservices.wapple.net/wapl.wsdl', array('connection_timeout' => 5));
- $isMobile = false;
-
- if($sClient)
- {
- $headers = array();
- foreach($_SERVER as $key => $val)
- {
- $headers[] = array('name' => $key, 'value' => $val);
- }
- // check if we are a mobile device
- $params = array(
- 'devKey' => "YOUR-DEV-KEY",
- 'deviceHeaders' => $headers
- );
-
-
- $xml = simplexml_load_string($sClient->getMobileDevice($params));
-
- if (trim($xml->mobile_device) == 1)
- {
- echo '<pre>';
- echo 'I AM A MOBILE DEVICE'."\n";
- echo 'Manufacturer: '.trim($xml->manufacturer)."\n";
- echo 'Model: '.trim($xml->model)."\n";
- echo '</pre>';
- }
- else
- {
- echo '<pre>';
- echo 'I AM A WEB BROWSER'."\n";
- echo 'Browser: '.trim($xml->manufacturer).' '.trim($xml->model)."\n";
- echo '</pre>';
- }
- }
-
- } catch (Exception $e){
- // Add your own exception handling here
- }
- ?>