How can I detect Android phones and Android tablets differently using the user agent header?
16,452
You can use PHP's $_SERVER['HTTP_USER_AGENT'] then case-insensitive eregi functions to look for the following, which assumes the browser developer followed Android's guidelines on user agent specification:
$ua = $_SERVER['HTTP_USER_AGENT'];
if (eregi('Android', $ua) && eregi('Mobile', $ua)) $platform = "Android Phone";
elseif (eregi('Android', $ua) && !eregi('Mobile', $ua)) $platform = "Android Tablet";
It's not foolproof but it's a start.
Related videos on Youtube
Author by
Tom
Updated on June 04, 2022Comments
-
Tom almost 2 years
For my site I need to be able to tell the difference between when an Android tablet visits and when an Android phone visits. It needs to be detected before the page is sent to the user so using JavaScript to check the screen res isn't an option.
At the moment I use this to detect an android device: stripos($ua, 'android')
Is there anything unique thar a tablet has in it's user agent?
-
Lie Ryan over 13 yearsIf you code your page using semantic HTML and CSS, then you should not need to detect device type before you send the page.
-