Home >Backend Development >PHP Tutorial >PHP gets device type instance code

PHP gets device type instance code

小云云
小云云Original
2018-03-09 13:13:201674browse

How to get the device type in php? This article mainly shares with you the example code of obtaining device type in PHP, hoping to help you.

<?php
  //获取USER AGENT
  $agent = strtolower($_SERVER[&#39;HTTP_USER_AGENT&#39;]);
  //分析数据
  $is_pc = (strpos($agent, &#39;windows nt&#39;)) ? true : false;
  $is_iphone = (strpos($agent, &#39;iphone&#39;)) ? true : false;
  $is_ipad = (strpos($agent, &#39;ipad&#39;)) ? true : false;
  $is_android = (strpos($agent, &#39;android&#39;)) ? true : false;
  //输出数据
  if($is_pc){
    echo "这是PC";
  }
  if($is_iphone){
    echo "这是iPhone";
  }
  if($is_ipad){
    echo "这是iPad";
  }
  if($is_android){
    echo "这是Android";
  }
?>

Related recommendations:

Get the device type of user login system + version number

PHP implements automatic jump according to the device type Page method

PHP method to automatically jump to the corresponding page according to device type_PHP

The above is the detailed content of PHP gets device type instance code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn