Home > Backend Development > PHP Tutorial > Get the device type system + version number the user logged in to

Get the device type system + version number the user logged in to

WBOY
Release: 2016-07-29 08:59:02
Original
1882 people have browsed it
<span>function </span><span>equipmentSystem(){
</span><span>$agent </span><span>= </span><span>isset</span><span>(</span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>]) ? </span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>] : </span><span>''</span><span>;
</span><span>if</span><span>(</span><span><em>stristr</em></span><span>(</span><span>$agent</span><span>,</span><span>'iPad'</span><span>)) {
</span><span>$fb_fs </span><span>= </span><span>"iPad"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/Android (([0-9_.]{1,3})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)) {
</span><span>$fb_fs </span><span>= </span><span>"</span><span>手机</span><span>(Android "</span><span>.</span><span>$version</span><span>[</span><span>1</span><span>].</span><span>")"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>stristr</em></span><span>(</span><span>$agent</span><span>,</span><span>'Linux'</span><span>)){
</span><span>$fb_fs </span><span>= </span><span>"</span><span>电脑</span><span>(Linux)"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/iPhone OS (([0-9_.]{1,3})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)){
</span><span>$fb_fs </span><span>= </span><span>"</span><span>手机</span><span>(iPhone "</span><span>.</span><span>$version</span><span>[</span><span>1</span><span>].</span><span>")"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/Mac OS X (([0-9_.]{1,5})+)/i'</span><span>,</span><span>$agent</span><span>,</span><span>$version</span><span>)){
</span><span>$fb_fs </span><span>= </span><span>"</span><span>电脑</span><span>(OS X "</span><span>.</span><span>$version</span><span>[</span><span>1</span><span>].</span><span>")"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/unix/i'</span><span>,</span><span>$agent</span><span>)){
</span><span>$fb_fs </span><span>= </span><span>"Unix"</span><span>;
</span><span>    }</span><span>else if</span><span>(</span><span><em>preg_match</em></span><span>(</span><span>'/windows/i'</span><span>,</span><span>$agent</span><span>)){
</span><span>$fb_fs </span><span>= </span><span>"</span><span>电脑</span><span>(Windows)"</span><span>;
</span><span>    }</span><span>else</span><span>{
</span><span>$fb_fs </span><span>= </span><span>"</span><span>未知</span><span>(Unknown)"</span><span>;
</span><span>    }</span><span>return </span><span>$fb_fs</span><span>;</span><span>}</span>
Copy after login

The above introduces the device type system + version number for obtaining user login, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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