判断客户端浏览器类型
01 | /** |
02 | * 判断浏览器名称和版本 |
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 | } |
时间: 2025-01-23 17:11:22