PHP gets device type instance code

小云云
Release: 2023-03-21 06:08:02
Original
1672 people have browsed it

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";
  }
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template