PHP Code _php tutorials for detecting mobile browsers

Source: Internet
Author: User
 
 
  1. Php
  2. function Is_mobile () {
  3. Returns true if one of the specified mobile browsers is detected
  4. $ Regex_match = "/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|" ;
  5. $ Regex_match. = "htc|dopod|blazer|netfront|helio|hosin|huawei|novarra| coolpad|webos|techfaith|palmsource| " ;
  6. $ Regex_match. = "blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo| maui| " ;
  7. $ Regex_match. = "Symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-| Portalmmm| " ;
  8. $ Regex_match. = "Jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220" ;
  9. $ Regex_match. = ")/I";
  10. return Isset ($_server[http_x_wap_profile]) or isset ($_server[http_profile]) or Preg_match ($regex _match, Strtolower ($ _server[http_user_agent]));
  11. }
  12. /*
  13. Allow the user A-to-force either the full or mobile versions of the Site-use a GET parameter on requests:
  14. Include likes to both versions of the site W/the Special Force mode parameters, mobile and full:
  15. < a href="Http://www.example.org/?mobile" >View Mobile Site a>
  16. < a href="Http://www.example.org/?full ">View full Site a>
  17. Always check for mobile or full parameters before accounting for any user-agent conditions:
  18. */
  19. if ($_get[mobile]) {
  20. $ Is_mobile = true ;
  21. }
  22. if ($_get[full]) {
  23. $ Is_mobile = false ;
  24. }
  25. if ($is _mobile) {
  26. Its-a mobile browser, do something
  27. Header ("Location:http://www.yoursite.com/mobile");
  28. } else {
  29. Its not a mobile browser, do something else
  30. Header ("Location:http://www.yoursite.com/desktop");
  31. Or instead of a redirect, simply build HTML below
  32. }
  33. ?>

http://www.bkjia.com/PHPjc/485997.html www.bkjia.com true http://www.bkjia.com/PHPjc/485997.html techarticle ? PHP functionis_mobile () {//returnstrueifoneofthespecifiedmobilebrowsersisdetected $ regex_match =/(nokia| Iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.li ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.