PHP determines whether it is an iPad

(*-*)浩
Release: 2023-02-27 12:12:02
Original
3195 people have browsed it

The example in this article describes how PHP simply determines iPhone, iPad, Android and PC devices. Share it with everyone for your reference. The details are as follows:

PHP determines whether it is an iPad

Because of work needs, we need to know what it is like. A user has visited my website. What is it now? There are many types of mobile devices. Let’s take a look at an example of PHP judging iPhone, iPad, Android, and PC devices compiled by the editor. (Recommended learning: PHP Video Tutorial)

I set the device using Windows system as PC. After all, the blog is for Chinese users, and most home devices still use Windows system.

The principle is to determine the USER AGENT submitted by the browser. The code is as follows:

<?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

The above is the detailed content of PHP determines whether it is an iPad. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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