How does PHP determine the type of user device accessing the system (code example)

不言
Release: 2023-04-05 13:22:02
forward
3549 people have browsed it

The content of this article is about how PHP determines the type of user device accessing the system (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

There are more and more electronic devices nowadays, and we often need to analyze the types of electronic devices used by users during the development process. The following is a PHP code used to obtain what types of electronic devices users use to access their platform.

/**
 * 用户设备类型
 * @return string
 */
function clientOS() {

    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if(strpos($agent, 'windows nt')) {
        $platform = 'windows';
    } elseif(strpos($agent, 'macintosh')) {
        $platform = 'mac';
    } elseif(strpos($agent, 'ipod')) {
        $platform = 'ipod';
    } elseif(strpos($agent, 'ipad')) {
        $platform = 'ipad';
    } elseif(strpos($agent, 'iphone')) {
        $platform = 'iphone';
    } elseif (strpos($agent, 'android')) {
        $platform = 'android';
    } elseif(strpos($agent, 'unix')) {
        $platform = 'unix';
    } elseif(strpos($agent, 'linux')) {
        $platform = 'linux';
    } else {
        $platform = 'other';
    }

    return $platform;
}
Copy after login

The above is the detailed content of How does PHP determine the type of user device accessing the system (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
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!