[教程] Typecho 判断WAP客户端

查看: 334|回复: 0
crll 发表于 2023-2-25 11:15:11
现在都是响应是主题,这种代码可能很少用到了。但是可能有特殊需要的可以用到。
我就整理一下发出来,说不上什么时候自己可以用到。
代码如下:


  1. <?php
  2. function wap(){
  3. if(@stristr($_SERVER['HTTP_VIA'],"wap")){
  4. return true;
  5. }elseif(strpos(strtoupper($_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){
  6. return true;
  7. }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'])){
  8. return true;
  9. }else{
  10. return false;
  11. }
  12. }
  13. ?>
复制代码
调用代码(以加载样式表为例):
  1. <?php if(wap()) { ?>
  2. <link rel="stylesheet" type="text/css" media="all" href="<?php $this->options->themeUrl('wap.css'); ?>" />
  3. <?php } else { ?>
  4. <link rel="stylesheet" type="text/css" media="all" href="<?php $this->options->themeUrl('style.css'); ?>"/>
  5. <?php } ?>
复制代码
博主论坛 bzlt.net
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于本站联系我们FAQ友情链接免责声明生存法则

Build with for "make" Copyright © 2020-2022. Powered by Discuz! GMT+8, 2024-4-20 20:40

快速回复 返回顶部 返回列表