不懂?没有人会嘲笑你;装懂?人人鄙视你;不懂,先研究;再不懂,就问吧!

PHP判断设备类型跳转相应页面

php xjmroots 2386℃ 0评论

PHP判断设备类型跳转相应页面,移动端设备跳转面向移动端的网页,PC端跳转面向PC端的网页

<?php
    //手机wap入口文件
      //判断终端是PC机还是移动端
      function isMobile(){ 
        $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; 
        $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:''; 
        function CheckSubstrs($substrs,$text){ 
          foreach($substrs as $substr)
            if(false!==strpos($text,$substr)){ 
              return true; 
            } 
            return false; 
        }
        $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');
        $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod'); 
        $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) || 
        CheckSubstrs($mobile_token_list,$useragent); 
        if ($found_mobile){ 
          return true; 
        }else{ 
          return false; 
        } 
      }

      //根据终端判断结果执行网页跳转
      function gourl()
      {
          if(isMobile())
          {
          //如果是手机客户端访问就跳转 http://localhost/wap.php      移动端网站页面
		    echo "<script>location.href='http://localhost/wap.php';</script>";

          }else{
          //如果不是手机客户端就访问跳转 http://localhost/index.php   PC端网站页面
		    echo "<script>location.href='http://localhost/index.php';</script>";
          }
      }

      gourl();
?>

 

转载请注明:家明的博客 » PHP判断设备类型跳转相应页面

喜欢 (1)or分享 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址