Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does php determine whether it is Android or ios development?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to judge whether php is Android or ios development, I believe most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it.

Php method to determine whether it is Android or ios: 1, create a PHP example file; 2, through the "function get_device_type () {...}" method to determine; 3, call the "Objective-C" function to get the phone type.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

Example 1: HTTP_USER_AGENT is mainly used, which means to check what operating system (including version number) the browser (including version number) and the user's personal preference code the visitor browsing the page is using.

The monitoring code is as follows:

Function get_device_type () {/ / all becomes lowercase $agent = strtolower ($_ SERVER ['HTTP_USER_AGENT']); $type =' other'; / / to judge if (strpos ($agent, 'iphone') | | strpos ($agent,' ipad')) {$type = 'ios';} if (strpos ($agent,' android')) {$type = 'android';} return $type;}

By calling the function Objective-C, you can get the type of the phone.

Example 2: only one judgment is needed

Example 3: this example may be a little off-topic, but it is also shared with you.

Function get_device_type () {/ / all lowercase $agent = strtolower ($_ SERVER ['HTTP_USER_AGENT']); $type =' other'; / / judge if (strpos ($agent,'iphone') respectively | | strpos ($agent,'ipad')) {$type = 'ios';} if (strpos ($agent,'android')) {$type =' android';} return$type;}

Finally, "buy three get one free", and then 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) {/ / non-Wechat browsers are prohibited from browsing echo "HTTP/1.1 401 Unauthorized";} else {/ / Wechat browser, which allows access to echo "MicroMessenger"; / / get the version number preg_match ('/. *? (MicroMessenger\ / ([0-9] +))\ spassport, $user_agent, $matches) Echo'

Version:'.$matches [2];}

The above is all the content of the article "how to determine whether php is Android or ios developer". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report