0

Possible Duplicate:
Simplest way to detect a mobile device

I am looking for a way to direct a mobile browser to one template, in expression engine, and a desktop/laptop browser to another template.

I am sure there is a simple way to do this but cannot think it it other than conditional css, but that will not be straight forward. Perhaps the best solution is to have javascript detect browser and fetch the ee template.

Community
  • 1
  • 1
vincentieo
  • 912
  • 2
  • 11
  • 26

2 Answers2

1

Have a look at the free add-ons MX Mobile Device Detect and Mobile.

Derek Hogue
  • 4,579
  • 1
  • 13
  • 27
1

I wrote this script to detect a mobile browser in PHP.

The code detects a user based on the user-agent string by preg_match()ing. It has 100% accuracy on all current mobile devices and I'm currently updating it to support more mobile devices as they come out. The code is called isMobile and is as follows:

function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}

You can use it like this:

// Use the function
if(isMobile())
    // Do something for only mobile users
else
    // Do something for only desktop users

To redirect a user to your mobile site, I would do this:

// Create the function, so you can use it
function isMobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
// If the user is on a mobile device, redirect them
if(isMobile())
    header("Location: http://m.yoursite.com/");

Let me know if you have any questions and good luck!

Justin DoCanto
  • 1,407
  • 1
  • 11
  • 8