Php method for obtaining the client browser name and version (based on ECShop function), _ PHP Tutorial

Source: Internet
Author: User
Php obtains the client browser name and version (based on the ECShop function ),. Php obtains the client browser name and version (based on the ECShop function). This example describes how to obtain the client browser name and version of php. For your reference, php obtains the client browser name and version (based on the ECShop function ),

This example describes how to obtain the browser name and version of the client in php. We will share this with you for your reference. The details are as follows:

The ecshop contains the get_user_browser () function to obtain the browser name and version. Although the obtained information is only some simple information, it is still very practical. The principle is to obtain the browser information through $ _ SERVER ['http _ USER_AGENT '], and then use regular expressions to compare the browser information.

The following figure shows the effects of various browsers:

The source code is as follows:

<?phpfunction 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();?>

I hope this article will help you with PHP programming.

Articles you may be interested in:
  • Php method for obtaining the user's browser version
  • PHP two methods for obtaining browser information and client location
  • PHP code used to obtain information about your browser and operating system
  • PHP judgment browser and judgment language code sharing
  • Php class for reading mobile client browsers
  • Summary of the four functions that PHP outputs to the browser
  • How php disables browsers from caching pages

Compile (based on the ECShop function). This article describes how to obtain the browser name and version of the client in php. Share it with you for your reference ,...

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.