Skip to content

Instantly share code, notes, and snippets.

@domdoescode
Created November 12, 2012 13:31
Show Gist options
  • Save domdoescode/4059407 to your computer and use it in GitHub Desktop.
Save domdoescode/4059407 to your computer and use it in GitHub Desktop.
Stupidly basic mobile detection =\
<?php
$mobileType = new stdClass();
//Detect special conditions devices
$mobileType->iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$mobileType->iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$mobileType->iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
if(stripos($_SERVER['HTTP_USER_AGENT'],"Android") && stripos($_SERVER['HTTP_USER_AGENT'],"mobile")) {
$mobileType->android = true;
} elseif (stripos($_SERVER['HTTP_USER_AGENT'],"Android")){
$mobileType->android = false;
$mobileType->androidTablet = true;
} else {
$mobileType->android = false;
$mobileType->androidTablet = false;
}
$mobileType->webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
$mobileType->blackBerry = stripos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$mobileType->rimTablet= stripos($_SERVER['HTTP_USER_AGENT'],"RIM Tablet");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment