Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-10-03 22:10:26

tollady
Member
Registered: 2006-12-06
Posts: 13

Andy Moore's PHP to detect mobiles script

Hey all,

Does anyone know how to implement Andy Moore’s PHP to detect mobiles script with textpattern?

I’ve been trying to add it to my existing index.php file but it breaks.

Any ideas?

Offline

#2 2007-10-05 23:10:30

obeewan
Archived Plugin Author
From: Stockholm, Sweden
Registered: 2004-08-12
Posts: 319
Website

Re: Andy Moore's PHP to detect mobiles script

At the top of your page (not in the index.php) add the following:

<txp:php>
   $mobilePhoneURL = "http://yoursite.mobi/";
  // 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'])){
    header('Location: $mobilePhoneURL');exit;
  }
  // 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')){
    header('Location: $mobilePhoneURL');exit;
  }
  // 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'])){
    header('Location: $mobilePhoneURL');exit;
  }
  // 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)])){
    header('Location: $mobilePhoneURL');exit;
  }
</txp:php>

Should do the trick. Ofcourse change the http://yoursite.mobi to wherever you are pointing your phoneusers to.


Plugins: ob1_advanced_search 1.032b, ob1_search_score 1.0, ob1_pagination 2.5, ob1_title 4.1, ob1_modified 2.1

“Let your plans be dark and as impenetratable as night, and when you move, fall like a thunderbolt.”
— Sun Tzu

Offline

#3 2007-11-07 21:11:46

Spot
Member
Registered: 2006-05-05
Posts: 39
Website

Re: Andy Moore's PHP to detect mobiles script

That produces a “200 OK” – “The document has moved here.”

With the “here” being a link to the .mobi site – is there a way to adjust the code to automatically redirect to that site?

Cheers


iMac 3.06 GHz 2 GB SDRAM
OSX 10.6.2

Offline

#4 2007-11-09 18:50:29

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Andy Moore's PHP to detect mobiles script

I’m interested too.
Perhaps with a kind of redirection :

header(
 "Location: http://yoursite.mobi/");
exit();

Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#5 2007-11-09 20:49:15

Spot
Member
Registered: 2006-05-05
Posts: 39
Website

Re: Andy Moore's PHP to detect mobiles script

Yes, I’ve tried adding

if(detect_mobile_device()){
  header('Location: http://david-hall.mobi/');
  exit;
}

to no avail.


iMac 3.06 GHz 2 GB SDRAM
OSX 10.6.2

Offline

#6 2007-11-14 20:53:30

Spot
Member
Registered: 2006-05-05
Posts: 39
Website

Re: Andy Moore's PHP to detect mobiles script

Think I’ll just make do with a stylesheet for now to serve the iPhone. Put with this in the head and devise a new mobile look :)

<link media=“only screen and (max-device-width: 480px)” href=“small-device.css” type=“text/css” rel=“stylesheet” >


iMac 3.06 GHz 2 GB SDRAM
OSX 10.6.2

Offline

Board footer

Powered by FluxBB