Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

DetectMobile

Summary: PHP API to determine whether the browser is a mobile device.
Version: 31-Dec-2008 (2.0.1)
Prerequisites: None
Status: Active
Maintainer: DaveG
Categories: Mobile, PDA, Cookbook
Download: ZIP or TAR
License: SHARED SOURCE LICENSE
Discussion: DetectMobile-Talk
Users: +4 (View / Edit)

Description

Provides a means of detecting whether the user browsing a wiki is using a mobile device. Can be used within PmWiki (or PHP in general) to either load mobile specific skins, or perform mobile related actions.

Download and Installation

  1. Download the script. (Download: ZIP or TAR)
Warning: the script contains some long lines, so if you open it in a text editor, be sure not to save the files with word-wrap on.
  1. Unzip it into your cookbook directory (usually pmwiki/cookbook/).
  2. Add the following to your local configuration file:
include_once("$FarmD/cookbook/detect_mobile.php");

Using the Script

Simply call the function from within PHP:

detect_mobile_device();

For example, you might use it in config.php to use a different skin if a mobile device is detected.

if(detect_mobile_device()) {
   $Skin = 'skidoo/PDA';
} else {
   $Skin = 'skidoo';
}

Optional Parameters

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

  • iPhone (default: true) - 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.
  • Android (default: true) - 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 (default: true) - 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.
  • Mobile Redirect URL (default: false) - 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 (default: false) - 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.

Known Issues

  • None so far...

Change Log

31-Dec-2008 (2.0.1)

Contributors: DaveG

  • new: Added sunrise to piped list.
  • chg: Altered structure of script; removed long-lines.
  • chg: Replaced use of eregi with preg_match (binary safety).
  • bug: Added check for PmWiki at header.

30-Dec-2008 (2.0.0)

Contributors: DaveG

  • Recognizes newer mobile devices.
  • Accepts 5 parameters to determine what to do with specific mobile devices that are capable of displaying full-version web pages.

7-Oct-2007 (1.0.0)

Contributors: DaveG

  • First release.

Credit

  • Mobile device detection is performed by the PHP script available from Andy Moore Dead link.

User notes +4: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on March 11, 2015, at 04:04 AM