判断客户端是IOS还是Android

PHP 判断客户端是IOS还是Android

<?php

if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
  echo 'systerm is IOS';
}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
  echo 'systerm is Android';
}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'miniprogram')){
  echo 'systerm is miniprogram';
}else{
  echo 'systerm is other';
}


?>

H5 页面判断客户端是IOS还是Android

<script type="text/javascript">
document.getElementById('openApp').onclick = function(e){

  if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
  {
    window.location.href = "yly://sq.51yna.com/Mall";//ios app协议
    window.setTimeout(function() {
      window.location.href = "https://itunes.apple.com/us/app/趣你/id1246665319?mt=8";
    }, 2000)
  }
  if(navigator.userAgent.match(/android/i))
  {
    window.location.href = "yly://sq.51yna.com/Mall";//android app协议
    window.setTimeout(function() {
      window.location.href = "http://sq.51yna.com/apk/sq.apk";//android 下载地址
    }, 2000)
  }
};
</script>

posted on 2017-12-07 16:45  *孤独的夜行者*  阅读(265)  评论(0编辑  收藏  举报

导航