PHP implementation of the method of judging mobile devices

Source: Internet
Author: User
This article mainly introduces PHP simple judgment of mobile device methods, involving PHP based on the server predefined variables to determine the operation of the relevant skills, the need for friends can refer to the next

Now the mobile internet is getting more and more, many websites have popularized the mobile browsing, in order to better let the Web page display on the mobile phone, we have chosen to use the CSS media query to make the response template, but there are drawbacks, such as the structure of some sites is CMS type, too much content to display, and the use of CSS Media query design response, will only hide but still loaded, in order to let the mobile phone side more quickly display content, we can use this PHP to determine the phone device code, using this code can be easily displayed or do not display the custom content.

This is the PHP Judgment phone device function code, copied to the PHP function library called:

<?phpfunction Is_mobile () {$user _agent = $_server [' http_user_agent '];      $mobile _browser = Array ("Mqqbrowser",//Mobile QQ Browser "Opera mobi",//Mobile phone Opera "Juc", "Iuc",//UC Browser "Fennec", "ios", "applewebkit/420", "applewebkit/525", "applewebkit/532", "ipad", "iphone" , "iPAQ", "ipod", "Iemobile", "Windows CE",//Windows Phone "240x320", "480x640", "Ace       R "," Android "," anywhereyougo.com "," Asus "," Audio "," BlackBerry "," Blazer "," Coolpad ", "Dopod", "Etouch", "Hitachi", "HTC", "Huawei", "Jbrowser", "Lenovo", "LG", " lg-"," lge-"," Lge "," Mobi "," Moto "," Nokia "," Phone "," Samsung "," Sony "," Sy  Mbian "," tablet "," Tianyu "," WAP "," XDA "," Xde "," ZTE ");  $is _mobile = false; foreach ($mobile _browser as $device) {if (Stristr ($user _agent, $device){$is _mobile = true;    Break }} return $is _mobile;}? >//This is the calling code, which can be combined with the IF Judgment: <?php if (Is_mobile ()):? >//set the contents of the mobile port <?php endif;?>

Summary: The above is the entire content of this article, I hope to be able to help you learn.

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.