Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Working Mechanic
Posted
I thought I'd ask if anyone has run into any great, as in fairly easy, ways of detecting mobile devices and redirecting to the correct site page, thus only needing one URL.

I've searched the net for this topic and it looks a bit scary.

Thanks in advance.
 
Posts: 26 | Registered: October 29, 2008Reply With QuoteEdit or Delete MessageReport This Post
Guru 'Geezer' Mechanic
Picture of larryd
Posted Hide Post
Here is a PHP solution (save it as index.php). Change the "index.html" to whatever page name you need it to be. I do not have any way to verify it works, nor know how complete the list of user agents is.

(Code deleted as it did not work.)

This message has been edited. Last edited by: larryd,
 
Posts: 5097 | Registered: December 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Working Mechanic
Posted Hide Post
Thanks for the reply. I can tell this jumb into mobile sites is going to thin out the thinning hair more. I took your script, changed the "index.htm" location to my mobile site page and tried to run it through several of the online mobile emulators...no luck.

Thanks again and let me know if anything comes to mind that I may be doing wrong.
 
Posts: 26 | Registered: October 29, 2008Reply With QuoteEdit or Delete MessageReport This Post
Working Mechanic
Posted Hide Post
I found this, which seems to work but I would like it to also redirect iphones, which it doesn't seem to do. If you home page isn't a php page, save it as one and insert the code below above the "Doctype" of your page. You will also need to change the link to your mobile site.

<?php
/*
SHARED LICENSE - VISIT ANDYMOORE.info
*/

function detect_mobile_device(){
// check if the user agent value claims to be windows but not windows mobile
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|iphone|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 tales 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-','alav','alca','amoi','audi','aste','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','opwv','palm','pana','pant','pdxg','phil','play','pluc','port','prox','qtek','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','w3c ','wap-','wapa','wapi','wapp','wapr','webc','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;

}

}



// example 1 - detect and redirect mobile browsers

if(detect_mobile_device()){

header('Location: http://yoursite.com/mobile/');

exit;

}


?>
 
Posts: 26 | Registered: October 29, 2008Reply With QuoteEdit or Delete MessageReport This Post
Guru 'Geezer' Mechanic
Picture of larryd
Posted Hide Post
Thanks for checking the code I posted. I deleted it since it did not work. No reason to leave bad code laying around.

Can you tell what the user agent is being reported by the iphone? The code you posted shows it is looking for the string "iphone" with case being ignored, but if is not being detected, that may not be the correct user agent.
 
Posts: 5097 | Registered: December 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Working Mechanic
Posted Hide Post
The source for this code is from the following sites:

http://mobiforge.com/developing/story/lightweight-devic...ion-php#comment-4816

http://www.dpinyc.com/literature/resources/code-bank/ph...ht-device-detection/

I have postings at both to try to get things to work better... If anyone feels so inclined, dive in.

Tom
 
Posts: 26 | Registered: October 29, 2008Reply With QuoteEdit or Delete MessageReport This Post
Junior Mechanic
Posted Hide Post
you can also try one of the on demand web services out there like handsetdetection.com

We also use it for geoip - to customise content based on location of the device browsing the site.
 
Posts: 1 | Registered: December 02, 2008Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 


™ & © 1998 - 2008, Virtual Mechanics Inc. All rights reserved.