There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: Windows Mobile and the web


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
26-Mar-2008, 04:40 AM #1
Solved: Windows Mobile and the web
I have some PDAs which use WM5 and I built a site which had an additional stylesheet for handheld devices. This worked fine. I've just received another PDA which uses WM6, but the same site doesn't display as it does on the WM5 PDAs. I think, to keep my sanity, it would be easier to build a mobile-specific sub-site, so was wondering how Google do this:

When I visit www.google.co.uk using a PDA (WM5 or WM6) it immediately returns me www.google.co.uk/m. How do Google detect my device is a mobile? What are they using? Because, basically, I want to be able to do the same.

Thanks,
__________________
Clive
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
26-Mar-2008, 05:02 PM #2
Try this one;
Code:
<?php

/*
PHP to detect mobile phones
*/

function detect_mobile_device(){
  
  // checks if the user agent claims to be windows but is windows mobile instead
  if(stristr($_SERVER['HTTP_USER_AGENT'],'windows')&&!stristr($_SERVER['HTTP_USER_AGENT'],'windows ce')){
    return false;
  }

  // check if the user agent gives away any tell tale signs it's a mobile browser

  if(eregi('up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp',$_SERVER['HTTP_USER_AGENT'])){
    return true;
  }

  // check the http accept header to see if wap.wml or wap.xhtml support is claimed
  if(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')){
    return true;
  }

  // check if there are any tell tale signs it's a mobile device from the _server headers
  if(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])){
    return true;
  }

  // build an array with the first four characters from the most common mobile user agents

  $a = array(
                    'acs-'=>'acs-',
                    'alav'=>'alav',
                    'alca'=>'alca',
                    'amoi'=>'amoi',
                    'audi'=>'audi',
                    'aste'=>'aste',
                    'avan'=>'avan',
                    'benq'=>'benq',
                    'bird'=>'bird',
                    'blac'=>'blac',
                    'blaz'=>'blaz',
                    'brew'=>'brew',
                    'cell'=>'cell',
                    'cldc'=>'cldc',
                    'cmd-'=>'cmd-',
                    'dang'=>'dang',
                    'doco'=>'doco',
                    'eric'=>'eric',
                    'hipt'=>'hipt',
                    'inno'=>'inno',
                    'ipaq'=>'ipaq',
                    'java'=>'java',
                    'jigs'=>'jigs',
                    'kddi'=>'kddi',
                    'keji'=>'keji',
                    'leno'=>'leno',
                    'lg-c'=>'lg-c',
                    'lg-d'=>'lg-d',
                    'lg-g'=>'lg-g',
                    'lge-'=>'lge-',
                    'maui'=>'maui',
                    'maxo'=>'maxo',
                    'midp'=>'midp',
                    'mits'=>'mits',
                    'mmef'=>'mmef',
                    'mobi'=>'mobi',
                    'mot-'=>'mot-',
                    'moto'=>'moto',
                    'mwbp'=>'mwbp',
                    'nec-'=>'nec-',
                    'newt'=>'newt',
                    'noki'=>'noki',
                    'opwv'=>'opwv',
                    'palm'=>'palm',
                    'pana'=>'pana',
                    'pant'=>'pant',
                    'pdxg'=>'pdxg',
                    'phil'=>'phil',
                    'play'=>'play',
                    'pluc'=>'pluc',
                    'port'=>'port',
                    'prox'=>'prox',
                    'qtek'=>'qtek',
                    'qwap'=>'qwap',
                    'sage'=>'sage',
                    'sams'=>'sams',
                    'sany'=>'sany',
                    'sch-'=>'sch-',
                    'sec-'=>'sec-',
                    'send'=>'send',
                    'seri'=>'seri',
                    'sgh-'=>'sgh-',
                    'shar'=>'shar',
                    'sie-'=>'sie-',
                    'siem'=>'siem',
                    'smal'=>'smal',
                    'smar'=>'smar',
                    'sony'=>'sony',
                    'sph-'=>'sph-',
                    'symb'=>'symb',
                    't-mo'=>'t-mo',
                    'teli'=>'teli',
                    'tim-'=>'tim-',
                    'tosh'=>'tosh',
                    'treo'=>'treo',
                    'tsm-'=>'tsm-',
                    'upg1'=>'upg1',
                    'upsi'=>'upsi',
                    'vk-v'=>'vk-v',
                    'voda'=>'voda',
                    'wap-'=>'wap-',
                    'wapa'=>'wapa',
                    'wapi'=>'wapi',
                    'wapp'=>'wapp',
                    'wapr'=>'wapr',
                    'webc'=>'webc',
                    'winw'=>'winw',
                    'winw'=>'winw',
                    'xda-'=>'xda-'
                  );

  // check if the first four characters of the current user agent are set as a key in the array

  if(isset($a[substr($_SERVER['HTTP_USER_AGENT'],0,4)])){
    return true;
  }
}

function detect_iphone(){
  if(eregi('iphone',$_SERVER['HTTP_USER_AGENT'])||eregi('ipod',$_SERVER['HTTP_USER_AGENT'])){
    return true;
  }
}

// example 1 - detect and redirect mobile browsers

if(detect_mobile_device()){
  header('Location: http://yoursite.com/mobile');
  exit;
}

// example 2 - detect and redirect desktop browsers

if(!detect_mobile_device()){
  header('Location: http://yoursite.com/');
  exit;
}

function detect_iphone(){
  if(eregi('iphone',$_SERVER['HTTP_USER_AGENT'])){
    return true;
  }
}

// example 3 - send iphone to specific site

if(detect_iphone()){
  header('Location: http://yoursite.com/iphone');
  exit;
}

?>
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
26-Mar-2008, 06:37 PM #3
Crikey! That's more than I'd expected! Will try it out, though.
Thanks,
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
27-Mar-2008, 11:14 AM #4
There are really just three site variations, and the script will detect the type and redirect to the site you created.

http://yoursite.com/mobile
http://yoursite.com/
http://yoursite.com/iphone

The array is for the most common types, there are alot of types out there and this works pretty good.
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
27-Mar-2008, 04:26 PM #5
Thanks for that. I'd assumed the iphone would use similar technology tp the other mobiles. Is it significantly different?

Sequal7, there are two functions testing for the iphone - I've used the longer one, which brings me to my next problem. I'm going to insert this as an include to return a different stylesheet instead of redirecting to a different sub-site (mainly because it a customised b2evo skin I am working on). That means the above script will be inserted and run every page request. Is that going to slow things down?
__________________
Clive

Last edited by DrP : 27-Mar-2008 05:15 PM.
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
27-Mar-2008, 06:24 PM #6
The script checks the user agent, it should not slow things down at all. This is done immediately.

I think the problem with css may be that the site entry point will be called when the link is run, but I guess your .css sheet could be run then in a subdomain?

There is a difference between the two type of phones..
iPhone is a full mac OS system running OS X (unlike Microsoft, which has a Windows-like UI on a completely different OS for their WM phones)
__________________
Good Luck on your fix

My real hobby..JoyCo
My real Job..(Second Hobby) IAFF Local 1865
Like the sites? My hobby is the one that created them!
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
28-Mar-2008, 06:19 AM #7
Your code works a treat! Previously, I had the following in the header:

<link rel="stylesheet" type="text/css" href="css/dinosaur.css" media="screen" />
<!--[if IE 7]> <link rel="stylesheet" type="text/css" href="css/IE7hacks.css" media="screen"> <![endif]-->
<!--[if IE 6]> <link rel="stylesheet" type="text/css" href="css/IE6hacks.css" media="screen"> <![endif]-->
<link href="css/mobile.css" rel="stylesheet" type="text/css" media="handheld" />

which meant mobile devices should read the handheld stylesheet and anything in it would overwrite the screen stylesheet. I think that's a waste of resources, because so much was repeated but changed in the mobile sheet, so it would be easier for mobiles to discard the screen sheet altogether and just use the mobile one.

What I've done is use your code to display either the link to the screen sheet or the link to mobile sheet, meaning the mobile device doesn't have to process two stylesheets. The most important thing of course, was that my WM6 device was ignoring the mobile stylesheet while my WM5 devices were using it. By only displaying a link to the relevant stylesheet, I've solved this problem. Thanks for your help!

If you want to see it in action then visit www.mrportman.co.uk, but I don't know how you'd view the source on a mobile device, so you wouldn't be able to see the link. It works though!

Oh, and going back to the iphone question. I've read it used Safari, which I think is standards compliant, so I don't need to treat it any differently to any other mobile device - meaning I can use the same mobile stylesheet.
__________________
Clive

Last edited by DrP : 28-Mar-2008 08:54 AM.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,208 posts.
 
Join Date: Oct 2006
28-Mar-2008, 10:47 AM #8
http://blogs.msdn.com/iemobile/archi...IE_Mobile.aspx
http://developer.apple.com/documenta...section_3.html

If you are only testing for WM5, WM6, and Safari Mobile than this should work:

PHP Code:
<?php
$mobileURL 
'http://example.com/m';
if (
preg_match('/Windows CE|iPhone|iPod/'$_SERVER['HTTP_USER_AGENT'])
    
header('Location: ' $mobileURL);
?>
Sequal7's Avatar
Computer Specs
Distinguished Member with 2,369 posts.
 
Join Date: Apr 2001
Location: Around the corner!
Experience: Including today?
28-Mar-2008, 01:29 PM #9
Glad it worked out for you, nice to see you used it to manipulate your own style.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:49 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.