PHP determines the browser type of the client

Source: Internet
Author: User
PHP judges the browser type of the client, determines the browser name and version, and determines the browser type of the client.
01 /**
02 * Determine the browser name and version
03 */
04 function get_user_browser ()
05 {
06 if (empty ($ _ SERVER ['http _ USER_AGENT '])
07 {
08 return '';
09}
10
11 $ agent = $ _ SERVER ['http _ USER_AGENT '];
12 $ browser = '';
13 $ browser_ver = '';
14
15 if (preg_match ('/MSIE \ s ([^ \ s |;] +)/I', $ agent, $ regs ))
16 {
17 $ browser = 'Internet Explorer ';
18 $ browser_ver = $ regs [1];
19}
20 elseif (preg_match ('/FireFox \/([^ \ s] +)/I', $ agent, $ regs ))
21 {
22 $ browser = 'Firefox ';
23 $ browser_ver = $ regs [1];
24}
25 elseif (preg_match ('/Maxthon/I', $ agent, $ regs ))
26 {
27 $ browser = '(Internet Explorer'. $ browser_ver. ') Maxthon ';
28 $ browser_ver = '';
29}
30 elseif (preg_match ('/Opera [\ s | \/] ([^ \ s] +)/I', $ agent, $ regs ))
31 {
32 $ browser = 'Opera ';
33 $ browser_ver = $ regs [1];
34}
35 elseif (preg_match ('/OmniWeb \/(v *) ([^ \ s |;] +)/I', $ agent, $ regs ))
36 {
37 $ browser = 'omniweb ';
38 $ browser_ver = $ regs [2];
39}
40 elseif (preg_match ('/Netscape ([\ d] *) \/([^ \ s] +)/I', $ agent, $ regs ))
41 {
42 $ browser = 'Netscape ';
43 $ browser_ver = $ regs [2];
44}
45 elseif (preg_match ('/safari \/([^ \ s] +)/I', $ agent, $ regs ))
46 {
47 $ browser = 'Safari ';
48 $ browser_ver = $ regs [1];
49}
50 elseif (preg_match ('/NetCaptor \ s ([^ \ s |;] +)/I', $ agent, $ regs ))
51 {
52 $ browser = '(Internet Explorer'. $ browser_ver. ') NetCaptor ';
53 $ browser_ver = $ regs [1];
54}
55 elseif (preg_match ('/Lynx \/([^ \ s] +)/I', $ agent, $ regs ))
56 {
57 $ browser = 'Lynx ';
58 $ browser_ver = $ regs [1];
59}
60
61 if (! Empty ($ browser ))
62 {
63 return addslashes ($ browser. ''. $ browser_ver );
64}
65 else
66 {
67 return 'unknow browser ';
68}
69}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.