Getting an iPhone UDID from Mobile Safari

There are four step to get UDID

1) Create .mobileconfig XML file for your website

2) When you hit/click .mobileconfig XML url. This pull up their provisioning settings on their phone & offers them an ‘Install’ button

3)The phone sends the data you requested in encrypted XML to the URL you set in your .mobileconfig

4) Process xml data and you will get UDID

1) Create .mobileconifg

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PayloadContent</key>
<dict>
<key>URL</key>
<string>http://www.sitename.com/info.php</string>
<key>DeviceAttributes</key>
<array>
<string>UDID</string>
<string>IMEI</string>
<string>ICCID</string>
<string>VERSION</string>
<string>PRODUCT</string>
</array>
</dict>
<key>PayloadOrganization</key>
<string>sitename.com Mobile Web App</string>
<key>PayloadDisplayName</key>
<string>sitename Profile</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadUUID</key>
<string>744e5abc-c5c4-4x3z-cvfa-d827e4a1d4c8</string>
<key>PayloadIdentifier</key>
<string>com.sitename.register-udid</string>
<key>PayloadDescription</key>
<string>By installing this profile, you'll allow sitename's mobile web app to know the UDID of your device and find apps available for installation on www.sitename.come/mobile
Only the UDID of your device will be transmitted to sitename. Nothing will be installed on the device.</string>
<key>PayloadType</key>
<string>Profile Service</string>
</dict>
</plist>

You’ll need to fill in your own URL and PayloadUUID. The PayloadUUID doesn’t have to be generated in a special way – just make sure it is unique to your app.

2) The User Views Your Provision Profile

PayloadOrganization and PayloadDescription are shown to the user when they see the profile. In my description
You don’t have to sign your .mobileconfig, but if you don’t then they will see a warning that it is not signed (see below).

Install profile image
Install profile image

3) Receiving the Requested Data

You will be redirected info.php page . add below code in this file

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

$plistBegin   = '<?xml version="1.0"';
$plistEnd   = '</plist>';
$pos1 = strpos($data, $plistBegin);
$pos2 = strpos($data, $plistEnd);
$data2 = substr ($data,$pos1,$pos2-$pos1);
$xml = xml_parser_create();
xml_parse_into_struct($xml, $data2, $vs);
xml_parser_free($xml);

$UDID = "";
$CHALLENGE = "";
$DEVICE_NAME = "";
$DEVICE_PRODUCT = "";
$DEVICE_VERSION = "";
$iterator = 0;

$arrayCleaned = array();
foreach($vs as $v){
if($v['level'] == 3 && $v['type'] == 'complete'){
$arrayCleaned[]= $v;
}
$iterator++;
}

$data = "";
$iterator = 0;

foreach($arrayCleaned as $elem){

$data .= "\n==".$elem['tag']." -> ".$elem['value']."<br/>";

switch ($elem['value']) {

case "CHALLENGE":

$CHALLENGE = $arrayCleaned[$iterator+1]['value'];

break;

case "DEVICE_NAME":

$DEVICE_NAME = $arrayCleaned[$iterator+1]['value'];

break;

case "PRODUCT":

$DEVICE_PRODUCT = $arrayCleaned[$iterator+1]['value'];

break;

case "UDID":

$UDID = $arrayCleaned[$iterator+1]['value'];

break;

case "VERSION":

$DEVICE_VERSION = $arrayCleaned[$iterator+1]['value'];

break;

}
$iterator++;
}

$params = "UDID=".$UDID."&CHALLENGE=".$CHALLENGE."&DEVICE_NAME=".$DEVICE_NAME."&DEVICE_PRODUCT=".$DEVICE_PRODUCT."&DEVICE_VERSION=".$DEVICE_VERSION;
// result_data is a directory

header('Location: http://www.sitename.com/result_data?'.$params);

4) Get Data

Note – “result_data” is a directory and not a page, I have created index.php in this page I get data in $_GET.
If you used script page insted of result data directory then it will give invalid profile while installing profile