DetectMobile
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
- Unzip it into your cookbook directory (usually
pmwiki/cookbook/
). - 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,
Just paste the following, after the include_once("$FarmD/cookbook/detect_mobile.php");
entry.
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 MooreDead 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.