Home > Backend Development > PHP Tutorial > PHP determines whether it is a mobile client, PHP determines whether it is a mobile client_PHP tutorial

PHP determines whether it is a mobile client, PHP determines whether it is a mobile client_PHP tutorial

WBOY
Release: 2016-07-12 09:08:18
Original
918 people have browsed it

PHP determines whether it is a mobile client, PHP determines whether it is a mobile client

<span><?</span><span>
function check_wap(){
    if(stristr($_SERVER['HTTP_VIA'],"wap")){// 先检查是否为wap代理,准确度高
        return true;
    }elseif(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){// 检查浏览器是否接受 WML.
        return true;
   }elseif(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){//检查USER_AGENT
        return true;             
    }else{
        return false;    
   }
   
}
if(check_wap() && !$_GET['m']){
    Header('Location:http://www.sdceo.com/?m=wap');
}
</span><span>?></span>
<span><!</span><span>DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span>></span>
<span><</span><span>html </span><span>xmlns</span><span>="http://www.w3.org/1999/xhtml"</span><span>></span>
<span><</span><span>head</span><span>></span>
<span><</span><span>meta </span><span>http-equiv</span><span>="Content-Type"</span><span> content</span><span>="text/html; charset=utf-8"</span> <span>/></span>
<span><</span><span>title</span><span>></span>php判断是否手机客户端<span></</span><span>title</span><span>></span>
<span></</span><span>head</span><span>></span>

<span><</span><span>body</span><span>></span>

<span></</span><span>body</span><span>></span>
<span></</span><span>html</span><span>></span>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1056600.htmlTechArticlePHP determines whether it is a mobile client, PHP determines whether it is a mobile client? function check_wap(){ if(stristr($ _SERVER['HTTP_VIA'],"wap")){// First check whether it is a wap proxy, with high accuracy return tr...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template