This article mainly introduces the function of get_user_browser() function in PHP ECShop. Interested friends can refer to it. I hope it will be helpful to everyone.
I saw that there is such a function get_user_browser() in ecshop to get the name and version of the browser. Although the information obtained is only simple information, it is still very practical. The principle is to obtain browser information through $_SERVER['HTTP_USER_AGENT'], and then use regular rules to compare and obtain the browser information.
The following is the effect of each browser:
##The source code is as follows :<?php function get_user_browser() { if (empty($_SERVER['HTTP_USER_AGENT'])) { return ''; } $agent = $_SERVER['HTTP_USER_AGENT']; $browser = ''; $browser_ver = ''; if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) { $browser = 'Internet Explorer'; $browser_ver = $regs[1]; } elseif (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) { $browser = 'FireFox'; $browser_ver = $regs[1]; } elseif (preg_match('/Maxthon/i', $agent, $regs)) { $browser = '(Internet Explorer ' .$browser_ver. ') Maxthon'; $browser_ver = ''; } elseif (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) { $browser = 'Opera'; $browser_ver = $regs[1]; } elseif (preg_match('/OmniWeb\/(v*)([^\s|;]+)/i', $agent, $regs)) { $browser = 'OmniWeb'; $browser_ver = $regs[2]; } elseif (preg_match('/Netscape([\d]*)\/([^\s]+)/i', $agent, $regs)) { $browser = 'Netscape'; $browser_ver = $regs[2]; } elseif (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) { $browser = 'Safari'; $browser_ver = $regs[1]; } elseif (preg_match('/NetCaptor\s([^\s|;]+)/i', $agent, $regs)) { $browser = '(Internet Explorer ' .$browser_ver. ') NetCaptor'; $browser_ver = $regs[1]; } elseif (preg_match('/Lynx\/([^\s]+)/i', $agent, $regs)) { $browser = 'Lynx'; $browser_ver = $regs[1]; } if (!empty($browser)) { return addslashes($browser . ' ' . $browser_ver); } else { return 'Unknow browser'; } } echo get_user_browser(); ?>
Sharing examples of two methods of converting PHP array encoding gbk and utf8 to each other
PHP implements replacement for multiple users Avatar function example sharing
PHP method to detect whether the URL can be opened normally
The above is the detailed content of Function of get_user_browser() function in PHP ECShop. For more information, please follow other related articles on the PHP Chinese website!