Last active
July 11, 2020 00:43
-
-
Save bkastl/7022253 to your computer and use it in GitHub Desktop.
mobile / not mobile detection via useragent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A lightweight mobile / not mobile detection. | |
Strings required to be recognized as mobile: | |
Mobi|Mini|Netfront|MOT|Maemo|Iris|Symbian|Fennec|Blazer|BOLT|GoBrowser|SEMC-Browser|Skyfire|TeaShark|Brew|uZard|Maemo|AvantGo|CHTML|PDA|MIDP|PPC|Smartphone|WebOS|PSP | |
Strings required to be recognized as tablet, when mobile: | |
iPad|Tablet|Kindle|tablet | |
Possible problems: | |
Kindle (right now, only Kindle Tablets?) | |
Example PHP for detecting mobile only, not tablet: | |
$useragent = $_SERVER['HTTP_USER_AGENT']; | |
$ismobile = (preg_match('/(Mobi|Mini|Netfront|MOT|Maemo|Iris|Symbian|Fennec|Blazer|BOLT|GoBrowser|SEMC-Browser|Skyfire|TeaShark|Brew|uZard|Maemo|AvantGo|CHTML|PDA|MIDP|PPC|Smartphone|WebOS|PSP)', $useragent) === 1 && preg_match('/(iPad|Tablet|Kindle)/i', $useragent) === 0); | |
User Agent Strings from: | |
http://www.useragentstring.com/pages/Mobile%20Browserlist/ | |
http://www.zytrax.com/tech/web/mobile_ids.html | |
thanks to @fhemberger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment