Detect Mobile User Agents & Browsers

Posted: January 31, 2012 in Mobile

Helping detect and better serve mobile browsers

Follow us on Twitter for updates! DetectMobiles

This PHP function lets you choose how to manage your mobile visitors, they can be redirected to a page built for mobiles or you can use it to decide which markup language and stylesheet to show that user.

It’s main function is to answer this question:

Is this visitor to my website using a mobile phone or PC?

Download Code

Download the code, unzip the archive then upload it to your website. Then view the usage guide or use the function generator to build a custom function to suit you and your mobile visitors.

 

Usage guide

It’s not rocket science, it’s easy to use!

But you need to understand at least basic PHP to get it working.

You need to include the file with the function then call the function before your PHP pages do anything else. See Support.

require_once('mobile_device_detect.php');
$mobile = mobile_device_detect();

The function has eight parameters that can be passed to it which define the way it handles different scenarios. These paramaters are:

  • iPhone – Set to true to treat iPhones as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect iPhones and iPods to.
  • iPad – Set to true to treat iPads as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect iPads to.
  • Android – Set to true to treat Android handsets as mobiles, false to treat them like full browsers or set a URL (including http://) to redirect Android and Google mobile users to.
  • Opera Mini – Set to true to treat Opera Mini like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Opera Mini users to.
  • Blackberry – Set to true to treat Blackberry like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Blackberry users to.
  • Palm – Set to true to treat Palm OS like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Palm OS users to.
  • Windows – Set to true to treat Windows Mobiles like a mobile, false to treat it like full browser or set a URL (including http://) to redirect Windows Mobile users to.
  • Mobile Redirect URL – This should be full web address (including http://) of the site (or page) you want to send mobile visitors to. Leaving this blank will make the script return true when it detects a mobile.
  • Desktop Redirect URL – This should be full web address (including http://) of the site (or page) you want to send non-mobile visitors to. Leaving this blank will make the script return false when it fails to detect a mobile.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s