PHP如何把手机用户跳转到手机版网页

如题所述

方式一:使用JavaScript
<script type="text/javascript">
//设定Mobile的定义(全小写)
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
//读取用户的浏览器资料
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
 
//检查开始
for (var i=0; i<mobileAgent.length; i++){
    if (browser.indexOf(mobileAgent[i])!=-1){
        isMobile = true;
        //alert(mobileAgent[i]);
        //程式码(转址)
        location.href = 'http://m.lineage.idv.hk/';
        //停止运行回圈
        break;
    }
}
</script>
方式二:使用PHP
<?php
//设定Mobile的定义
$mobileAgent = array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
//读取用户的浏览器资料
$browser = $_SERVER['HTTP_USER_AGENT'];
$isMobile = false;
 
//检查开始
foreach($mobileAgent as $search){
    if(stristr($browser,$search)!=false){
        $isMobile = true;
        //echo $search;
        //程式码(转址)
        header("Location: http://m.lineage.idv.hk/");
        //停止运行程序
        exit;
    }
}
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-09
//通过检测用户ua来识别
if(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'])){
    header('Location: 你的手机版本地址');    
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网