Mobile - detect or redirect


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



Copy this code and paste it in your HTML
  1. /*********** Detect ***********/
  2.  
  3. $agent = $_SERVER['HTTP_USER_AGENT'];
  4.  
  5. if(preg_match('/iPhone|Android|Blackberry/i', $agent)){
  6. echo "You're using a mobile device.";
  7. }
  8.  
  9. /*********** Redirect ***********/
  10.  
  11. $agent = $_SERVER['HTTP_USER_AGENT'];
  12.  
  13. if(preg_match('/iPhone|Android|Blackberry/i', $agent)){
  14. header("Location: mobile.html");
  15. exit;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.