Detect Only Mobile Users with "Desktop Mode" Browsers - php
I know that there are many ways to detect mobiles users (mainly by checking the user agent).
But many mobile browsers have the so called "desktop mode", which provides a bit more functional environment for websites.
Is there a way to provide a specific feature (e.g. a jQuery slider) only to these mobile users, browsing in this mode? The real issue I am having is that, essentially, their user agent is the same in both modes (e.g. "Opera Mini 9.0.1"), so from a webmaster's standpoint - how do I know that they are on a mobile device but are browsing the site in desktop mode?
Here's the relevant code for iOS Safari users. Essentially the User Agent loses the reference to iPhone/iPod/iPad in desktop mode, but that info is still present in navigator.platform:
var iOSAgent = window.navigator.userAgent.match(/iPhone|iPod|iPad/);
var iOSPlatform = window.navigator.platform && window.navigator.platform.match(/iPhone|iPod|iPad/);
var iOSRequestDesktop = (!iOSAgent && iOSPlatform);
On Android Chrome, "Desktop Mode" removes the "Android" string from the user agent. If you can use JavaScript, the following mostly detects Android Chrome Desktop Mode:
var webkitVer = parseInt(/WebKit\/([0-9]+)|$/.exec(navigator.appVersion)[1], 10); // also matches AppleWebKit
var isGoogle = webkitVer && navigator.vendor.indexOf('Google') === 0; // Also true for Opera Mobile and maybe others
var isAndroid = isGoogle && userAgent.indexOf('Android') > 0; // Careful - Firefox and Windows Mobile also have Android in user agent
var androidDesktopMode = !isAndroid && isGoogle && (navigator.platform.indexOf('Linux a') === 0) && 'ontouchstart' in document.documentElement;
It makes the assumption that Chrome with an ARM processor is Android. The assumption definitely fails for users running Linux on ARM, fails for Android on i686 or MIPS etc (and I haven't been able to test ChromeOS).
For Windows Mobile, you can detect desktop mode by checking for the string "WPDesktop;" in the user agent.
Edit: The code used to use window.chrome and window.chrome.webstore which was a reliable test, but somewhere around Chrome 65 you couldn't use those properties anymore to detect desktop mode. Thanks to #faks for the info.
Edit 2: I now highly recommend against treating "desktop mode" as "mobile mode" but, here are my updated opinions:
beware that code detecting desktop mode is really fragile and newer browser versions regularly break sniffing code techniques
unless you have a serious bug or critical usability issue, it totally isn't worth sniffing
never sniff if you are not actively maintaining the code and testing against beta versions of browsers
I use the following for iOS: navigator.vendor.indexOf('Apple') === 0 && 'ontouchstart' in document.body. We need this to set the astonishingly shitty iOS inputMode correctly for iPadOS 13 (old navigator.platform technique now broken in iOS 13 Beta) and avoid other iOS usability bugs with other input types. I think you can check window.screen.width == 768 to sniff iPad (stays same even if orientation change). The sniff will break if Macbook comes out in a touch version.
I now use the following for detecting Android desktop mode: 'ontouchstart' in document.body && navigator.platform.indexOf('Linux a') === 0 && (window.chrome || (window.Intl && Intl.v8BreakIterator)). Horrible unreliable sniff, but we really need it because android viewport and pinch zooming (not page zooming) is really broken on Android for our SPA (screen size is not enough as a desktop touch user can use a small window).
If detecting OS/Platform is not the concern, then you can go for this.
const screenWidth = window.screen.width;
const isMobile = screenWidth <= 480;
const isTablet = screenWidth <= 1024;
There can be a few high-end tablets with width up to 1280px;
Code which may be well to test:
let screenWidth = window.screen.width;
let isMobile = screenWidth <= 480;
let details = navigator.userAgent;
let regexp = /android|iphone|kindle|ipad/i;
let isMobileDevice = regexp.test(details);
if (isMobileDevice && isMobile) {
document.write("You are using a Mobile Device");
} else if (isMobile) {
document.write("You are using Desktop on Mobile"); // the most interesting
} else {
document.write("You are using Desktop");
}
Related
Is there a way within PHP to detect color scheme for the browsers system [duplicate]
Lately I am updating my software to support dark mode, in response to research that looking at a paper-white background display is bad for the eyes and for sleep rhythms. Is there a way to detect from PHP that a user's browser and/or OS are set to Dark Mode? How about detecting that it is set to nighttime mode (reduction of blue colors)?
Unfortunately the dark mode detection methodology does not exist for server side-processing (including PHP). All efforts thus-far by the W3C (and its sponsors) has been focused on client-side / Jamstack, and the Media Queries Level 5 specification uses a prefers-color-scheme media query for detection. This useful in both CSS and JavaScript. There is a recommendation by Thomas Steiner (#DenverCoder9) from Google to implement a Proposed server-side client hint, but this has not been adopted (yet?) by the W3C or the browsers. Either way - there is a significant drawback in server-side detection (both with Thomas' recommendation and my solution below) in that the server will only know about a state change (e.g. macOS "Auto" mode when night fall happens) on the next server request, or more visibly, the first load of the page. The recommendation is to leave this detection on the client and projects like vinorodrigues/bootstrap-dark show how easy that can be - without server-side processing. Having said that - there is a workaround: The most efficient way is to leverage the js-cookie/js-cookie project, and include the following code into your HTML pages: <script src="https://cdn.jsdelivr.net/npm/js-cookie/dist/js.cookie.min.js"></script> <script> // code to set the `color_scheme` cookie var $color_scheme = Cookies.get("color_scheme"); function get_color_scheme() { return (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light"; } function update_color_scheme() { Cookies.set("color_scheme", get_color_scheme()); } // read & compare cookie `color-scheme` if ((typeof $color_scheme === "undefined") || (get_color_scheme() != $color_scheme)) update_color_scheme(); // detect changes and change the cookie if (window.matchMedia) window.matchMedia("(prefers-color-scheme: dark)").addListener( update_color_scheme ); </script> And then your PHP will detect this cookie like this: $color_scheme = isset($_COOKIE["color_scheme"]) ? $_COOKIE["color_scheme"] : false; if ($color_scheme === false) $color_scheme = 'light'; // fallback Which you can use to load the CSS: // Load the CSS for the correct color-scheme if ($color_scheme == 'dark') { ?><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/vinorodrigues/bootstrap-dark#0.0/dist/bootstrap-night.min.css"><?php } else { ?><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0.css/bootstrap.css"><?php } Or, like this: ?>You are in <?= $color_scheme ?> mode.<?php
Since PHP executes on the server without any knowledge of the client, there is no direct way of finding this out. If it is possible to detect the color mode in JS, you could embed a small JS script to your site, that sets a cookie. Cookies are transmitted to the server on request, so PHP is able to query them.
(PHP) How to detect that user's computer/browser is in Dark Mode?
Lately I am updating my software to support dark mode, in response to research that looking at a paper-white background display is bad for the eyes and for sleep rhythms. Is there a way to detect from PHP that a user's browser and/or OS are set to Dark Mode? How about detecting that it is set to nighttime mode (reduction of blue colors)?
Unfortunately the dark mode detection methodology does not exist for server side-processing (including PHP). All efforts thus-far by the W3C (and its sponsors) has been focused on client-side / Jamstack, and the Media Queries Level 5 specification uses a prefers-color-scheme media query for detection. This useful in both CSS and JavaScript. There is a recommendation by Thomas Steiner (#DenverCoder9) from Google to implement a Proposed server-side client hint, but this has not been adopted (yet?) by the W3C or the browsers. Either way - there is a significant drawback in server-side detection (both with Thomas' recommendation and my solution below) in that the server will only know about a state change (e.g. macOS "Auto" mode when night fall happens) on the next server request, or more visibly, the first load of the page. The recommendation is to leave this detection on the client and projects like vinorodrigues/bootstrap-dark show how easy that can be - without server-side processing. Having said that - there is a workaround: The most efficient way is to leverage the js-cookie/js-cookie project, and include the following code into your HTML pages: <script src="https://cdn.jsdelivr.net/npm/js-cookie/dist/js.cookie.min.js"></script> <script> // code to set the `color_scheme` cookie var $color_scheme = Cookies.get("color_scheme"); function get_color_scheme() { return (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) ? "dark" : "light"; } function update_color_scheme() { Cookies.set("color_scheme", get_color_scheme()); } // read & compare cookie `color-scheme` if ((typeof $color_scheme === "undefined") || (get_color_scheme() != $color_scheme)) update_color_scheme(); // detect changes and change the cookie if (window.matchMedia) window.matchMedia("(prefers-color-scheme: dark)").addListener( update_color_scheme ); </script> And then your PHP will detect this cookie like this: $color_scheme = isset($_COOKIE["color_scheme"]) ? $_COOKIE["color_scheme"] : false; if ($color_scheme === false) $color_scheme = 'light'; // fallback Which you can use to load the CSS: // Load the CSS for the correct color-scheme if ($color_scheme == 'dark') { ?><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/vinorodrigues/bootstrap-dark#0.0/dist/bootstrap-night.min.css"><?php } else { ?><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0.css/bootstrap.css"><?php } Or, like this: ?>You are in <?= $color_scheme ?> mode.<?php
Since PHP executes on the server without any knowledge of the client, there is no direct way of finding this out. If it is possible to detect the color mode in JS, you could embed a small JS script to your site, that sets a cookie. Cookies are transmitted to the server on request, so PHP is able to query them.
Browser Detection with Javascript
Reasoning for this Question I am aware that browser detection can never be 100% reliable as the User Agent header can always be forged, however, I am not bothered by this. Although there are many questions on this topic, they all seem to be quite old, so to get an up to date answer I felt I should ask this question again. I am currently detecting the browser name and version server side using the PHP browscap, and then returning the name and version into javascript variables (not a very good method). The reason why I need to do this is simply to display a message to visitors if they are not using a supported browser. Current method (something similar): <script type="text/javascript"> var browser = new Array(); browser['browser'] = '<?php echo $browser_name; ?>'; browser['version'] = '<?php echo $browser_version; ?>'; browser['error'] = '<?php echo $browser_error; ?>'; </script> It would be much better to do this client side as the browscap can be quite slow, and it would prevent me having to pass values into javascript variables from PHP. If you think using PHP is a better method then please state in your answer, this is just my opinion. Question Therefore, my question quite simply, is the following link a reliable method for determining the browser name and version? Javascript Detect I am aware that new browsers will need to be added to this, this does not bother me. I am more concerned about whether the algorithm used is reliable. Thanks in advance UPDATE 1 To see what I mean, take a look at https://www.icloud.com/ in Internet Explorer 7 or less. You will receive a message saying that the browser is not supported. This is easy to do for IE as you can simply use the <!--[if gt IE..., however, I need to test all browsers.
This does not look right, you can fetch browser information from Javascript. No need to mix JS and PHP code to do that. You can do something like this to fetch, and detect user browser with just JavaScript: var userAgent = navigator.userAgent.toLowerCase(); var old = false; // Internet Explorer 7 if (userAgent.indexOf('msie 7.0b') !== -1) { old = true; } else if (userAgent.indexOf('msie 7.0') !== -1) { old = true; } // Internet Explorer 6 else if (userAgent.indexOf('msie 6.1') !== -1) { old = true; } else if (userAgent.indexOf('msie 6.01') !== -1) { old = true; } else if (userAgent.indexOf('msie 6.0b') !== -1) { old = true; } else if (userAgent.indexOf('msie 6.0') !== -1) { old = true; } ... // Detect any other browser versions you consider old if(old = true) { // Show notification and alert users that they are using old browser } This is how you can do it using JS, but you can also use HTML to achieve this: <!--[if lte IE 6]> // include your .css style or do whatever you want to alert users their browser is old <![endif]--> Short answer to your question is YES, its wrong to detect user browser the way you do it, since you can do it with plain JavaScript, or even with HTML. No need to mix PHP and JS code here, and at the end, both PHP and JS will get the same UserAgent info.
Explanation After extensive research and discussing amongst other developers, it is clear that there is no reliable method for retrieving the browser name and version from the User Agent. This is down to several reasons: The format of a browsers User Agent can change at any time if the developers of the browser so wish to do so. This could immediately prevent some scripts from working correctly. Users can forge their User Agents to mimic other browsers, and therefore would appear to be using a browser they are not. Possible Solutions Whilst I hugely discourage the use of these scripts as they could stop working at the release of an update to any browser anytime, if you do wish to detect the browser name and version in Javascript then I would advise using this script: Javascript Detect However, the most reliable method for retrieving the details of the browser is without a doubt the browscap supplied by Gary Keith. The browscap project offers extensive information about each browser and OS gathered from the User Agent. It is very easy to implement and even easier to use. To read more, take a look at: Gary Keith - Browscap If you choose to use the browscap by Gary Keith, you will need to ensure it is updated weekly at the very least. Answer Whilst I am contradicting myself with this answer, it is clear that detecting the browser information with any sort of script is not advised. The only reliable method of browser detection is that of the Internet Explorer HTML conditions, and as stated, these only cover Internet Explorer. Try to avoid browser specific functions and notices, and make use of the built in features such as: media="only screen and (device-width: 768px)" and <!--[if IE 8]>I am IE 8<![endif]-->
This question needs an updated answer. I think the best option these days for client-side detection is WURFL. Its an updated library of devices based on Useragents - think Browscap for the client side. Load the JS and it returns JSON based on the device that requested the js. Perfect! <script type="text/javascript" src="//wurfl.io/wurfl.js"></script> Because it does the parsing on the WURFL server side, you need to load the js remotely and not save it in your dir tree. A super easy WURFL.is_mobile is all it takes to determine mobile for example. Good luck.
You could try having a look at navigator.appName and navigator.userAgent.
The yepnopejs IE detection (!ie prefixes) works by utilizing the MS conditional comments. A short snippet for detecting versions of IE prior to IE10 in JavaScript without resorting to user-agent sniffing. while ( div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->' ); // … https://github.com/SlexAxton/yepnope.js/blob/master/prefixes/yepnope.ie-prefix.js yepnope usage example: yepnope({ load: ['normal.js', 'ie6!ie7!ie-patch.js'] // patch for ie6 or ie7 only });
You can use a perfect plugin for this information written in jQuery (like javascript) look at this link: https://github.com/jquery/plugins.jquery.com Be sure to do feature detection instead of browser detection when you want to determine if a certain feature is available in a browser, apply bugfixes, etc.
how to check if the request came from mobile or computer in php
i need to check if the request came from a mobile phone device or desktop computer using php please help. thanks
I am using a function to identify mobile browsers in my projects, which can detect almost all major Mobile Operating systems and browsers. function ismobile() { $is_mobile = '0'; if(preg_match('/(android|up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) { $is_mobile=1; } if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) { $is_mobile=1; } $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4)); $mobile_agents = array('w3c ','acs-','alav','alca','amoi','andr','audi','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-'); if(in_array($mobile_ua,$mobile_agents)) { $is_mobile=1; } if (isset($_SERVER['ALL_HTTP'])) { if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) { $is_mobile=1; } } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) { $is_mobile=0; } return $is_mobile; }
Check the $_SERVER['HTTP_USER_AGENT'] for mobile user agents. You should check out http://detectmobilebrowser.com/ for already existing scripts to detect for mobile browsers (it just uses the user agents).
You can try The WURFL PHP API or Tera-Wurfl
http://mobiledetect.net/ is another lightweight php class, but you mist keep in mind that checking User-agent is a good but not perfect way, the issue is rules are constantly out-dated and incomplete so you need to change the detection code continuously. Also check https://modernizr.com/ for another way to detect.
Nowadays, what do you consider "a mobile device"? User agent parsers will give very good results, except for rare edge cases. The problem is that you have to constantly update them if you store the data locally or depend on the service being online if you use it "in the cloud". It is better to use a functionality detection library, e.g. Modernizr, send to your server information about the browser capabilities on first visit and serve appropriate content based on what the browser can or cannot do. Or even better, delegate that to Javascript.
The desktop browser usually sends requests with the following header: Sec-CH-UA-Mobile: ?0 The browser on the mobile device usually sends requests with the following header: Sec-CH-UA-Mobile: ?1 So, you could check this using code like the following: if (isset($_SERVER['HTTP_SEC_CH_UA_MOBILE']) && $_SERVER['HTTP_SEC_CH_UA_MOBILE']=='?1') { ... }
Simple Smart Phone detection
Ok I've seen a couple of mobile detection scripts that look to identify all mobile handsets, anyone come up with a simple Smart Phone detection script? I'm using the jQueryMobile framework and wanted to theme based on device, Am I going about this the wrong way or are there any tips one could give? What defines a Smart Phone? What I've seen but I think are way to complex for smartphone detection: HDAPI Zend UserAgent PHP get_browser() WURFL PHP API PHP Lightweight Mobile Detection I like this function here but still needs to be trimmed down: /** * A simple class used to detect whether page<br> * is being viewed from a mobile device or not. * #copyright 2010 Covac Software * #author Christian Sciberras * #version 01/05/2010 */ class Mobile { public static function is_mobile(){ $user_agent = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed $accept = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed return false || (preg_match('/ipad/i',$user_agent)) || (preg_match('/ipod/i',$user_agent)||preg_match('/iphone/i',$user_agent)) || (preg_match('/android/i',$user_agent)) || (preg_match('/opera mini/i',$user_agent)) || (preg_match('/blackberry/i',$user_agent)) || (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i',$user_agent)) || (preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)) || (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i',$user_agent)) || ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)) || (isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])) || (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','501i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=>'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bird'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'=>'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','ezze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=>'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=>'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=>'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=>'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n302'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=>'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=>'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'=>'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'=>'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=>'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','yas-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=>'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','ccwa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=>'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','jemu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=>'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','prox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'=>'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=>'winw','wmlb'=>'wmlb','xda-'=>'xda-',))) ; } } UPDATE: Another approach I thought of was the Mobile OS and then filter by device, ANyone have thoughts on this? Another interesting link: PHP to Detect Browser and Operating System
I am not pretty sure if I understand what you are trying to achieve and with "wanted to theme based on device". So, will you put a BlackBerry logo if the user has a BlackBerry device (so it should be dependent on the manufacturer) or will your web app be denpendent on the screen size? Or depenedent on the features of HTML5/CSS3? Also in web development I try to do one website for all. The same I do with jQuery Mobile and it works great. I did one design, which works for Opera (Win), Firefox (Win + Mac), IE9, Safari (Win, Mac, iPad), Google Chrome (Win). And I do no CSS hacks! Your web app should be nearly independent of the screen size, I only have css media limitations and some JavaScript functions which design the page. If you want to check the HTML5 / CSS3 support of the webbrowser, you should never check the mobile device itself, you need to check the function itself. So, bad style is checking if the webbrowser is IE in version 7, 8, 9, because you will never know which function will work in which version. You check the functionality you need. And this can be done with Modernizr: http://diveintohtml5.ep.io/detect.html#modernizr http://www.modernizr.com/ Other checks, jQuery can handle it.
There are so many different mobile devices and so little standardization, and you probably would need to update your detection script from time to time as well as add new devices to the list. I found that www.handsetdetection.com has pretty complete list of handsets you can download. Also you can use their API for the real time detection on their side. I don't know how it works on your app but I'd recommend to add detection info to your users' cookies in order to make api calls only for the unique devices. Here is an example how I did this in startup plugin for ZF project class Application_Plugin_HandsetDetection extends Zend_Controller_Plugin_Abstract { public function routeStartup(Zend_Controller_Request_Abstract $request) { $cookies = Zend_Controller_Action_HelperBroker::getStaticHelper('Cookies'); if ($cookies->isVersion('mobile')) { $this->getResponse()->setRedirect($mobile); } if ($cookies->isVersion('full')){ return; } $device = new Application_Service_HandsetDetection(); if (!$device->isMobile()) { $cookies->setVersion('full'); return; } $cookies->setVersion('mobile'); $this->getResponse()->setRedirect($mobile); } }