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