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.