Skip to content

Instantly share code, notes, and snippets.

@ArupSen
Created December 16, 2013 17:05
Show Gist options
  • Save ArupSen/7990438 to your computer and use it in GitHub Desktop.
Save ArupSen/7990438 to your computer and use it in GitHub Desktop.
PHP device sniffer. Do stuff on the server side.
<?php
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
//do something with this information
if( $iPod || $iPhone ){
//browser reported as an iPhone/iPod touch -- do something here
}else if($iPad){
//browser reported as an iPad -- do something here
}else if($Android){
//browser reported as an Android device -- do something here
}else if($webOS){
//browser reported as a webOS device -- do something here
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment