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 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; }
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!