php method to determine whether it is Android or ios: 1. Create a PHP sample file; 2. Implement the judgment through the "function get_device_type(){...}" method; 3. Call the "Objective-C" function Just get the phone type.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
PHP determines whether the mobile phone is IOS or Android
This article introduces three small examples of using PHP to determine whether a mobile phone is IOS or Android. To determine whether the user's mobile phone is Android or iOS, I searched for relevant information and shared the final results with everyone. .
Example 1: Mainly uses HTTP_USER_AGENT, which means it is used to check what operating system (including version number) browser (including version number) the visitor browsing the page is using. number) and the user's personal preference code.
The monitoring code is as follows:
function get_device_type() { //全部变成小写字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type = 'other'; //分别进行判断 if(strpos($agent, 'iphone') || strpos($agent, 'ipad')) { $type = 'ios'; } if(strpos($agent, 'android')) { $type = 'android'; } return $type; }
By calling the Objective-C function, the type of mobile phone can be obtained.
Example 2: All you need is one judgment
<?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{ echo 'systerm is other'; } ?>
Example 3: This example may be a little off topic but I will share it with you.
function get_device_type() { //全部变成小写字母 $agent = strtolower($_SERVER['HTTP_USER_AGENT']); $type ='other'; //分别进行判断 if(strpos($agent,'iphone') || strpos($agent,'ipad')) { $type ='ios'; } if(strpos($agent,'android')) { $type ='android'; } return$type; }
Finally, "Buy 3 and get one free", let me share with you a small example that has little to do with this topic:
php determines whether the page is opened by WeChat
$user_agent = $_SERVER['HTTP_USER_AGENT']; if (strpos($user_agent, 'MicroMessenger') === false) { // 非微信浏览器禁止浏览 echo "HTTP/1.1 401 Unauthorized"; } else { // 微信浏览器,允许访问 echo "MicroMessenger"; // 获取版本号 preg_match('/.*?(MicroMessenger\/([0-9.]+))\s*/', $user_agent, $matches); echo '<br>Version:'.$matches[2]; }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine if PHP is developing for Android or iOS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
