How to easily detect mobile devices


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function mobileCheck(){
  2. $mobile = isset($_GET['mobile']) ? true : false;
  3. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  4.  
  5. $devices = array('iPhone','iPod','iPad');
  6.  
  7. foreach($devices as $device){
  8. if(strpos($user_agent,$device) || $mobile == true) return true;
  9. }
  10. return false;
  11. }

URL: http://www.dropthenerd.com/how-to-easily-detect-mobile-devices/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.