Typecho 判断WAP客户端

No Reply , Posted in 代码 on September 28, 2014

现在都是响应是主题,这种代码可能很少用到了。但是可能有特殊需要的可以用到。
我就整理一下发出来,说不上什么时候自己可以用到。
代码如下:

<?php
function wap(){
    if(@stristr($_SERVER['HTTP_VIA'],"wap")){
        return true;
    }elseif(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){
        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'])){
        return true;
    }else{
        return false;
    }
}
?>

调用代码(以加载样式表为例):

<?php if(wap()) { ?>
    <link rel="stylesheet" type="text/css" media="all" href="<?php $this->options->themeUrl('wap.css'); ?>" />
<?php } else { ?>
    <link rel="stylesheet" type="text/css" media="all" href="<?php $this->options->themeUrl('style.css'); ?>"/>
<?php } ?>

标签: 判断, wap