Windows Phone Thoughts - Daily News, Views, Rants and Raves

Check out the hottest Windows Mobile devices at our Expansys store!


Digital Home Thoughts

Loading feed...

Laptop Thoughts

Loading feed...

Android Thoughts

Loading feed...




Go Back   Thoughts Media Forums > WINDOWS PHONE THOUGHTS > Windows Phone Developer

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2003, 09:00 PM
Jason Dunn
Executive Editor
Jason Dunn's Avatar
Join Date: Aug 2006
Posts: 29,160
Default Mobile Device Re-Direct Code

Webmasters, listen up: if you'd like to create a version of your site for mobile devices, the first step is to create code that will detect the type of device hitting the site (or, more accurately, its browser). The sniffer code to do so, developed by Fabrizio Fiandanese, looks like this:

Code:
&lt;?<br /><br />if (stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or stristr($ua,<br />"Mazingo") or stristr($ua, "Mobile") or stristr($ua, "T68")  or stristr($ua,<br />"Syncalot") or stristr($ua, "Blazer") )<br />{<br />     $DEVICE_TYPE="MOBILE";<br />}<br /><br />if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE")<br />{<br />     $location='mobile/index.php';<br />     header ('Location: '.$location);<br />     exit;<br />}<br /><br />?>
<br /><br />You can also use Javascript version that detects any Windows-CE client:<br /><br />
Code:
&lt;script><br />var isCE = navigator.appVersion.indexOf("Windows CE")>0;<br />if (isCE)<br />{<br /> window.location.href="mobile/";<br />}<br />&lt;/script>
<br /><br />Place the above at the very top of your index page, and when a mobile device hits it, it will be re-directed to your mobile page. The industry standard is <a href="www.domain.com/mobile/index.htm">www.domain.com/mobile/index.htm</a> (or .php, .asp, etc.). From there it's a matter of building the appropriate components into your mobile site. At the very least, if you're running a retail business, include contact information, your business hours, etc. If your Web site is dynamic, with your content separated from the templates, you should be able to include your data in a mobile device-friendly format.<br /><br />It's also a good idea to include a link on your mobile page back to the desktop home page, this time with a version that doesn't have the sniffer code - for those people who are running more capable mobile device browsers, or desperately need something off your site.
 
Reply With Quote
  #2  
Old 07-22-2003, 09:09 PM
entropy1980
Oracle
Join Date: Aug 2006
Posts: 864

Thank you....I had been using somthing similar but had a few problems with those darn OSS browsers :?
 
Reply With Quote
  #3  
Old 07-22-2003, 09:14 PM
PhatCohiba
Intellectual
Join Date: Feb 2002
Posts: 145

Thanks Jason.

Now if we can only get more sites to worry about reformating.

-John
 
Reply With Quote
  #4  
Old 07-22-2003, 09:20 PM
merlin
Ponderer
Join Date: Jul 2004
Posts: 59

I've been using this code for ASP pages:


Code:
&lt;%

'	This specifically tests for Pocket IE on Pocket PC 2002 by searching for the "PPC" string within
'	the User Agent field. "PPC" is only inclued in the USER AGENT header field on Pocket PC 2002.

	userAgent = Request.ServerVariables("HTTP_USER_AGENT")
	

	isPocketPc = false



	'	This check to see if the browser is any version of MSIE on Windows CE. That way, if the browser
	'	gets updated, this should still detect that it is from a Windows CE machine.

	if(userAgent &lt;> "" AND (InStr(userAgent, "PPC") > 0)) then
		
		isPocketPc = true

	end if

	if isPocketPc then
		

		'	If the user is connecting with a pocket pc, then we redirect them to another page.

		response.redirect("mobile/index.htm")

	end if
%>
 
Reply With Quote
  #5  
Old 07-22-2003, 09:23 PM
entropy1980
Oracle
Join Date: Aug 2006
Posts: 864

Quote:
Originally Posted by merlin
I've been using this code for ASP pages:


Code:
&lt;%

'	This specifically tests for Pocket IE on Pocket PC 2002 by searching for the "PPC" string within
'	the User Agent field. "PPC" is only inclued in the USER AGENT header field on Pocket PC 2002.

	userAgent = Request.ServerVariables("HTTP_USER_AGENT")
	

	isPocketPc = false



	'	This check to see if the browser is any version of MSIE on Windows CE. That way, if the browser
	'	gets updated, this should still detect that it is from a Windows CE machine.

	if(userAgent &lt;> "" AND (InStr(userAgent, "PPC") > 0)) then
		
		isPocketPc = true

	end if

	if isPocketPc then
		

		'	If the user is connecting with a pocket pc, then we redirect them to another page.

		response.redirect("mobile/index.htm")

	end if
%>
The problem I see is that PPC is sometimes the UA of Mac's so some Mac browsers start getting the mobile version...
 
Reply With Quote
  #6  
Old 07-22-2003, 09:25 PM
Iglesiab
Pupil
Join Date: Mar 2004
Posts: 27

Quote:
It's also a good idea to include a link on your mobile page back to the desktop home page
Could someone tell me where this is on the mobile pocketpcthoughts.com. I must keep overlooking it and a few times I really could have used it. Thanks
 
Reply With Quote
  #7  
Old 07-22-2003, 09:41 PM
bdeli
Thinker
Join Date: Jul 2003
Posts: 312

Cool - thnx!
__________________
"Life is a dream. The only real thing is you." -unknown
 
Reply With Quote
  #8  
Old 07-22-2003, 09:45 PM
Jason Dunn
Executive Editor
Jason Dunn's Avatar
Join Date: Aug 2006
Posts: 29,160

Quote:
Originally Posted by Iglesiab
Quote:
It's also a good idea to include a link on your mobile page back to the desktop home page
Could someone tell me where this is on the mobile pocketpcthoughts.com. I must keep overlooking it and a few times I really could have used it. Thanks
Oh, uh, well, umm... ops: Give us a few minutes. :wink:
__________________
Want to contact me personally? Use this. Want to read my personal blog? Check it out. Want to follow me on Twitter? Here you go.
 
Reply With Quote
  #9  
Old 07-22-2003, 09:45 PM
dean_shan
Mystic
Join Date: Feb 2004
Posts: 1,911

Thank you Fabrizio :werenotworthy: I have been trying to figure out how to do this for the longest time. Many thanks!
 
Reply With Quote
  #10  
Old 07-22-2003, 09:52 PM
Duncan
Pontificator
Join Date: Jul 2003
Posts: 1,468

This will be very useful - thanks for spreading the wealth Jason!
 
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 PM.