ID Win Phone User agent and provide a link in a list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
HoldenFJ
Forum Newbie
Posts: 4
Joined: Wed Dec 28, 2011 4:46 pm

ID Win Phone User agent and provide a link in a list

Post by HoldenFJ »

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?

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>';
	        ?>            
Thanks in advance for your suggestions and help.
Post Reply