This article mainly introduces three examples for PHP to determine whether a mobile phone is IOS or Android, interested friends can refer to this article to introduce three small instances in PHP for judging whether the mobile phone is IOS or Android. to determine whether the user's mobile phone is Android or ios, I searched the relevant materials and shared the final results with you.
Instance 1:HTTP_USER_AGENT is used to check the operating system (including the version) browser (including the version number) and user preference code used by page visitors.
The monitoring code is as follows:
Function get_device_type () {// All are lowercase letters $ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']); $ type = 'other '; // Determine if (strpos ($ agent, 'iPhone ') | strpos ($ agent, 'iPad') {$ type = 'iOS ';} if (strpos ($ agent, 'Android') {$ type = 'Android';} return $ type ;}
By callingObjective-CThis function can obtain the mobile phone type.
Instance 2:Only one judgment is needed.
<?phpif(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';}?>
Instance 3:This instance may have some questions but I will share them with you.
Function get_device_type () {// All are lowercase letters $ agent = strtolower ($ _ SERVER ['http _ USER_AGENT ']); $ type = 'other '; // Determine if (strpos ($ agent, 'iPhone ') | strpos ($ agent, 'iPad') {$ type = 'iOS ';} if (strpos ($ agent, 'Android') {$ type = 'Android';} return $ type ;}
Finally, "Buy 3 get one free" will share with you a small instance that has little to do with this topic:
Php checks whether the page is open
$ User_agent = $ _ SERVER ['http _ USER_AGENT ']; if (strpos ($ user_agent, 'micromessenger') === false) {// you are not allowed to browse echo "HTTP/1.1 401 Unauthorized";} else {// The browser allows access to echo "MicroMessenger"; // you can obtain the preg_match ('/. *? (MicroMessenger \/([0-9.] +) \ s */', $ user_agent, $ matches); echo'
Version: '. $ matches [2];}
The above is the three-step PHP code for judging whether the mobile phone is IOS or Android. I hope you will like it and make persistent efforts to provide more practical articles for everyone.