
07-22-2003, 09:00 PM
|
Executive Editor
Join Date: Aug 2006
Posts: 29,160
|
|
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:
<?<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:
<script><br />var isCE = navigator.appVersion.indexOf("Windows CE")>0;<br />if (isCE)<br />{<br /> window.location.href="mobile/";<br />}<br /></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.
|
|
|
|
|

07-22-2003, 09:09 PM
|
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 :?
|
|
|
|
|

07-22-2003, 09:14 PM
|
Intellectual
Join Date: Feb 2002
Posts: 145
|
|
Thanks Jason.
Now if we can only get more sites to worry about reformating.
-John
|
|
|
|
|

07-22-2003, 09:20 PM
|
Ponderer
Join Date: Jul 2004
Posts: 59
|
|
I've been using this code for ASP pages:
Code:
<%
' 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 <> "" 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
%>
|
|
|
|
|

07-22-2003, 09:23 PM
|
Oracle
Join Date: Aug 2006
Posts: 864
|
|
Quote:
Originally Posted by merlin
I've been using this code for ASP pages:
Code:
<%
' 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 <> "" 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...
|
|
|
|
|

07-22-2003, 09:25 PM
|
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
|
|
|
|
|

07-22-2003, 09:41 PM
|
Thinker
Join Date: Jul 2003
Posts: 312
|
|
Cool - thnx!
__________________
"Life is a dream. The only real thing is you." -unknown
|
|
|
|
|

07-22-2003, 09:45 PM
|
Executive Editor
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:
|
|
|
|
|

07-22-2003, 09:45 PM
|
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!
|
|
|
|
|

07-22-2003, 09:52 PM
|
Pontificator
Join Date: Jul 2003
Posts: 1,468
|
|
This will be very useful - thanks for spreading the wealth Jason!
|
|
|
|
|
|
|