php验证当前是设备是电脑端还是手机端

<?php

    // 验证设备为PC还是WAP
    $agent = $_SERVER['HTTP_USER_AGENT'];
    if(strpos($agent,"comFront") ||
    strpos($agent,"iPhone") ||
    strpos($agent,"MIDP-2.0") ||
    strpos($agent,"Opera Mini") ||
    strpos($agent,"UCWEB") ||
    strpos($agent,"Android") ||
    strpos($agent,"Windows CE") ||
    strpos($agent,"SymbianOS"))
    {

      // 走到这里即为手机端,可跳转到手机端页面
      $url = 'http://手机端网址'.$_SERVER['REQUEST_URI'];
      header("Location:".$url);  // 重定向页面
      exit;
    }

 

posted @ 2020-08-30 12:51  齐云海  阅读(245)  评论(1编辑  收藏  举报