|
Cookbook /
DetectMobileSummary: Determines whether the browser is a mobile device.
Version: 31-Dec-2008 (2.0.1)
Prerequisites: None
Status: Active
Maintainer: DaveG
Download: detect_mobile.zipΔ
License: SHARED SOURCE LICENSE
DescriptionProvides 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
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.
include_once("$FarmD/cookbook/detect_mobile.php");
Using the ScriptSimply call the function from within PHP: detect_mobile_device(); For example, you might use it in
if(detect_mobile_device()) {
$Skin = 'skidoo/PDA';
} else {
$Skin = 'skidoo';
}
Optional ParametersThe function has five parameters that can be passed to it which define the way it handles different scenarios. These parameters are:
Known Issues
Change Log31-Dec-2008 (2.0.1)Contributors: DaveG
30-Dec-2008 (2.0.0)Contributors: DaveG
7-Oct-2007 (1.0.0)Contributors: DaveG
Credit
CommentsI'd love to know if you use this recipe -- edit this page and leave a comment below! 28-December-2008: (Ian MacGregor) I installed this script as per your instructions above and was presented with this error: Parse error: syntax error, unexpected T_IF in public/cookbook/detect_mobile.php on line 119
UPDATE: 20081230 - Dave, I tried it again using only command line tools to download, unpack, and setup the local config.php file and it's no longer yielding any errors. However, the recipe works fine on my website from a desktop computer, but doesn't switch skins when viewed on my mobile phone. I think the reason for this is that the mobile phone I have, Sidekick LX, uses the following user agent string: Mozilla/5.0 (Danger hiptop 2.0; U; AvantGo 3.2) I think the recipe is seeing that user agent string as 'mozi' which is also used in the Firefox web browser for desktop environments, thus the skin switch isn't happening. Is there a way to detect the "AvantGo" or "hiptop" bits of the above user agent string? I think that would help a great deal for Sidekick, Sidekick Color, Sidekick2, Sidekick3, Sidekick Slide, Sidekick LX, and Sidekick08 users. I'm planning to switch phones in the next few months to the T-Mobile G1 and the user agent string for that phone is: Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 But, being a Linux user myself, the best way to detect that user agent string is to detect either "Android" or "Mobile" as anything else will likely see browsers used under the desktop Linux OS as mobile when they aren't. Ian MacGregor
|