Posted By

MrFjords on 10/20/10


Tagged

php mobile


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

martins
mloberg
adth
ashleysheinwald


Mobile - detect or redirect


 / Published in: PHP
 

  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  

You need to login to post a comment.