Home > PHP Framework > YII > body text

yii2.0 determines ios or Android

angryTom
Release: 2020-02-18 10:04:12
Original
1944 people have browsed it

This article mainly introduces an example of how YII2 determines whether a mobile phone is IOS or Android. Interested friends can refer to it.

yii2.0 determines ios or Android

yii2.0 determines whether ios or Android

mainly uses HTTP_USER_AGENT, which means it is used to check browsing Code for the operating system (including version number), browser (including version number) and user preference that the visitor to the page is using.

The detection code is as follows:

function get_device_type(){
     //全部变成小写字母
     $agent = strtolower(Yii::$app->request->userAgent);
     $type = 'other';
       //分别进行判断
     if(strpos($agent, 'iphone') || strpos($agent, 'ipad')){
         $type = 'ios';
     }

     if(strpos($agent, 'android')){
         $type = 'android';
     }
     return $type;
}
Copy after login

By calling the get_device_type function, you can get the type of mobile phone.

Recommended related articles and tutorials: yii tutorial

The above is the detailed content of yii2.0 determines ios or Android. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!