Your Ad Here

Posted By

anvilcity on 08/27/10


Tagged

iphone


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

roli000
shawntysco


PHP methods for iPhone and iPod detection


 / Published in: PHP
 

URL: http://www.iphonemicrosites.com/tutorials/php-auto-bowser-detection/

References: http://us3.php.net/function.get-browser http://us2.php.net/strpos

http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html

http://stackoverflow.com/questions/186734/how-do-i-detect-mobile-safari-server-side-using-php

  1. < ?php
  2. $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") ||
  3. strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
  4. if ($browser == true) { echo 'Code You Want To Execute'; }
  5. ?>
  6.  
  7. or
  8.  
  9. <?php
  10. $browser = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone") ||
  11. strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
  12. if ($browser == true) { header("Location: http://www.example.com/"); }
  13. ?>
  14.  
  15. More advanced method that detects Mobile Safari:
  16.  
  17. <?php
  18. /* detect Mobile Safari */
  19. $browserAsString = $_SERVER['HTTP_USER_AGENT'];
  20. if (strstr($browserAsString, " AppleWebKit/") && strstr($browserAsString, " Mobile/"))
  21. {
  22. $browserIsMobileSafari = true;
  23. }
  24. ?>

Report this snippet  

You need to login to post a comment.