ID Win Phone User agent and provide a link in a list
Posted: Thu Jan 12, 2012 4:21 pm
On my web site I am attempting to :
1 - Write a function to identify the Window Phone Mobile device
2 - echo a link for that device if the device exists that sends the device to the windows phone app store: zune://navigate/?appID=**************************. I don't want to send users to a specific mobile site (I've seen lots of examples on how to do that), only provide them one tailored link if they have a Windows phone.
3 - Else echo a link tailored for a desktop browser. http://windowsphone.com/s?appId=*******************************
My HTML code only executes to the point where the function exists, so syntax may be an issue; however, does this approach work in principle?
Thanks in advance for your suggestions and help.
1 - Write a function to identify the Window Phone Mobile device
2 - echo a link for that device if the device exists that sends the device to the windows phone app store: zune://navigate/?appID=**************************. I don't want to send users to a specific mobile site (I've seen lots of examples on how to do that), only provide them one tailored link if they have a Windows phone.
3 - Else echo a link tailored for a desktop browser. http://windowsphone.com/s?appId=*******************************
My HTML code only executes to the point where the function exists, so syntax may be an issue; however, does this approach work in principle?
Code: Select all
<?php
function mobileDevice() {
$type = $_SERVER['HTTP_USER_AGENT'];
if(strpos((string)$type, "Windows Phone") != false)
return true;
else
return false;
}
?>
<?php
//Calling the function in a list.
if(mobileDevice() == true) {
echo '<dd id="d4"><a href="zune://navigate/?appID=*************************" title="Windows Phone Marketplace" target="_blank">Windows Phone Marketplace</a></dd>';
}
else
echo '<dd id="d4"><a href="http://windowsphone.com/s?appId=*********************************" title="Windows Phone Marketplace" target="_blank">Windows Phone Marketplace</a></dd>';
?>