Title: PHP Browser Detection
Author: Mindshare Labs, Inc.
Published: <strong>2010 年 1 月 29 日</strong>
Last modified: 2015 年 9 月 8 日

---

搜索插件

**该插件尚未通过WordPress的最新3个主要版本进行测试**。 当与较新版本的WordPress一起
使用时，可能不再受到维护或支持，并且可能会存在兼容性问题。

![](https://ps.w.org/php-browser-detection/assets/icon-256x256.png?rev=999338)

# PHP Browser Detection

 作者：[Mindshare Labs, Inc.](https://profiles.wordpress.org/mindshare/)

[下载](https://downloads.wordpress.org/plugin/php-browser-detection.3.1.8.zip)

 * [详情](https://cn.wordpress.org/plugins/php-browser-detection/#description)
 * [评价](https://cn.wordpress.org/plugins/php-browser-detection/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/php-browser-detection/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/php-browser-detection/#developers)

 [支持](https://wordpress.org/support/plugin/php-browser-detection/)

## 描述

Version 3 adds support for is_tablet(), is_desktop(), and is_browser() as well as
numerous bug fixes and code improvements. As of version 3.1.2 automatic updates 
of browscap.ini are disabeld until we can deal with memory usage issues.

PHP Browser Detection is a WordPress plugin used to detect a user’s browser. It 
can be used to send conditional CSS files for Internet Explorer, display different
content or custom messages anywhere on the page, or to swap out Flash for an image
for iPhones.

**Template Tags:**

_Test for specific browsers:_

$version is optional. Include a major version number, a single integer – 3,4,5, 
etc… Or leave it empty to test for any version.

    ```
    <?php if(is_firefox($version)) { /* your code here */ }; ?>

    <?php if(is_safari($version)) { /* your code here */ }; ?>

    <?php if(is_chrome($version)) { /* your code here */ }; ?>

    <?php if(is_opera($version)) { /* your code here */ }; ?>

    <?php if(is_ie($version)) { /* your code here */ }; ?>

    <?php if(is_browser($name, $version)) { /* your code here */ }; ?>
    ```

_Check for mobile, tablet, iPhone, iPad, iPod, etc…_

    ```
    <?php if(is_desktop()) { /* your code here */ }; ?>

    <?php if(is_tablet()) { /* your code here */ }; ?>

    <?php if(is_iphone($version)) { /* your code here */ }; ?>

    <?php if(is_ipad($version)) { /* your code here */ }; ?>

    <?php if(is_ipod($version)) { /* your code here */ }; ?>

    <?php if(is_mobile()) { /* your code here */ }; ?>
    ```

_Check for greater than / less than a specific version…_

Less than or equal to Firefox 19:
 < ?php if(is_firefox() && get_browser_version()

Less than or equal to IE 10:
 < ?php if(is_ie() && get_browser_version()

Greater than or equal to Safari 4:
 = 4) { /* your code here */ }; ?>

these are just a few examples, but this syntax will work for any browser or version.

_Check specific versions…_

Is the browser IE6?

Is the browser IE10?

**Or you can get all the info and do what you want with it:**

_Get just the name…_

    ```
    <?php $browser_name = get_browser_name(); ?>
    ```

Get the full version number – 3.2, 5.0, etc…

    ```
    <?php $browser_version = get_browser_version(); ?>
    ```

_Or get it all in array…_

    ```
    <?php $browser_info = php_browser_info(); ?>
    ```

**Shortcodes:**

_Test for specific browsers:_

    ```
    [is_browser name="chrome" version="45"]
    <p>You are using Chrome 45 or above.</p>
    [/is_browser]
    ```

_Output all browser info:_

    ```
    [browser_info]
    ```

## 安装

 1. Automatically install through the Plugin Browser or…
 2. Upload entire `php-browser-detection` folder to the `/wp-content/plugins/` directory.
 3. Activate the plugin through the ‘Plugins’ menu in WordPress.

## 常见问题

  PHP Browser Detection is reporting the version of Chrome (or any pother browser)
as “0.0”

This means the local cached copy of the browscap.ini user agent database is out 
of date. You can fix this by updating the file yourself manually, or wait for a 
new release of the plugin. To update the file, download the most recent version 
here: http://browscap.org/stream?q=PHP_BrowsCapINI and save it over the one bundled
with the plugin `php-browser-detection/cache/browscap.ini`

  I got a fatal error on activation. What gives?

This most likely means your web host is running a very old version of PHP. As of
version 3.0, only PHP 5.3 and above are supported. You can ask your host to upgrade
PHP for you.

## 评价

![](https://secure.gravatar.com/avatar/c0b2465d6819d479eb9bbc16c73076f59fd5854f84c4cb58b9efe3a0447be217?
s=60&d=retro&r=g)

### 󠀁[Not working with IE, Edge and mobile.](https://wordpress.org/support/topic/not-working-with-ie-edge-and-mobile/)󠁿

 [PUShAUNE](https://profiles.wordpress.org/pushaune/) 2018 年 1 月 28 日

This plugin is outdated. It works fin to detect FireFox, Opera and Chrome ; but 
fails to detect IE, Edge, or even mobiles.

![](https://secure.gravatar.com/avatar/c5201ff4593f9d4aa29b9c6ceca6043c87bbabbddd197775dc6397fa6f3fdb22?
s=60&d=retro&r=g)

### 󠀁[Works great for browser-specific css](https://wordpress.org/support/topic/works-great-for-browser-specific-css/)󠁿

 [DPGrant](https://profiles.wordpress.org/dpgrant/) 2016 年 9 月 3 日

Of course this can be used to provide different CSS for firefox, chrome, and ie/
Edge browsers. But I’m also using it to distinguish between emulations of different
generations of ie browsers. A super-useful plugin.

![](https://secure.gravatar.com/avatar/2bb3340cba1fd2ba725c4e155138e017d20121c528aa2f99d8fd1fbd134f90ff?
s=60&d=retro&r=g)

### 󠀁[Very nice](https://wordpress.org/support/topic/very-nice-602/)󠁿

 [THRIVE – Web Design Gold Coast](https://profiles.wordpress.org/deanoakley/) 2016
年 9 月 3 日

This worked great for us. It deservers a better rating. Thank you!

![](https://secure.gravatar.com/avatar/7303b33ec5006e17085555421333ff4360f9dd41472933aa1cc6e666ef2336c2?
s=60&d=retro&r=g)

### 󠀁[great](https://wordpress.org/support/topic/great-3923/)󠁿

 [mtadams4](https://profiles.wordpress.org/mtadams4/) 2016 年 9 月 3 日

Awesome plugin giving users a lot of flexibility!

![](https://secure.gravatar.com/avatar/ab389810dd9503dc6ea81d507a9364318753686fb59d0b38242bdc258d6a9e85?
s=60&d=retro&r=g)

### 󠀁[Works and is VERY welcome](https://wordpress.org/support/topic/works-and-is-very-welcome/)󠁿

 [Smat Placid](https://profiles.wordpress.org/www_smatplacid_com/) 2016 年 9 月 
3 日 1 回复

I love this plugin! Thanks guys. Would be nice to have shortcodes as well – to be
able to write some content for desired browsers/ platform. Anyway – head up and 
keep rockin’

 [ 阅读所有16条评价 ](https://wordpress.org/support/plugin/php-browser-detection/reviews/)

## 贡献者及开发者

「PHP Browser Detection」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ Mindshare Labs, Inc. ](https://profiles.wordpress.org/mindshare/)
 *   [ MartyThornley ](https://profiles.wordpress.org/martythornley/)

[帮助将「PHP Browser Detection」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/php-browser-detection)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/php-browser-detection/)，
查看[SVN仓库](https://plugins.svn.wordpress.org/php-browser-detection/)，或通过[RSS](https://plugins.trac.wordpress.org/log/php-browser-detection/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/php-browser-detection/)。

## 更新日志

#### 3.1.8

 * Add missing include file
 * Confirm filters aren’t working (needs refactor)

#### 3.1.7

 * Added shortcodes

#### 3.1.6

 * Bugfix for 3.1.5

#### 3.1.5

 * Updated Browscap to 2.0.5
 * Re-enable auto-updates
 * Added filter to turn off auto updates for host with low memory.
 * Added FAQ about manually updating.
 * Added global variable for `$browser_info = php_browser_info();`

#### 3.1.4

 * Updated default browscap.ini

#### 3.1.3

 * Updated default browscap.ini
 * Migrated Browscap.php to use asgrim’s fork
 * Added ID param for tests

#### 3.1.2

 * Disabled auto updates because of memory problems
 * Minor bugfixes
 * Add icons for WP 4.0 plugin installer
 * Added development repo on github.com
 * Updated Browscap library

#### 3.1.1

 * Fix for is_desktop()
 * Added is_true

#### 3.1

 * Updated default browscap.ini
 * Changed version of browscap to utilize less memory
 * Updated Browscap to version 2.0 from 2b

#### 3.0.1

 * Added FAQ section

#### 3.0

 * Browscap.ini database auto-updates!
 * Browscap database caching!
 * Added is_tablet()
 * Added is_desktop()
 * Added is_browser()
 * Various detection fixes (incl. Opera Mini and IE Mobile)
 * Updated tests
 * Refactored plugin structure
 * Now utilizes Browser Capabilities PHP Project by Garet Jax

#### 2.2.4

 * updated php_browser_detection_browscap.ini to version 5027

#### 2.2.3

 * updated readme

#### 2.2.2

 * updated php_browser_detection_browscap.ini to version 5022
 * bugfixes

#### 2.2.1

 * updated php_browser_detection_browscap.ini to version 5020
 * bugfixes
 * additional testing and QA

#### 2.2

 * updated php_browser_detection_browscap.ini to version 5020 (custom version)
 * minor code cleanup
 * added tests.php to check all plugin features
 * added additional usage examples to readme.txt
 * deprecated is_ie9() functions in favor is is_ie(9), etc.
 * fixed issue with is_ipod
 * fixed issue with is_mobile
 * fixed issue with detecting Android 4.2.*
 * fixed issue with boolean values
 * other minor bug fixes reported on wordpress.org

#### 2.1.3

 * updated php_browser_detection_browscap.ini to version 5016

#### 2.1.2

 * updated php_browser_detection_browscap.ini to version 5004

#### 2.1.1

 * updated php_browser_detection_browscap.ini to version 4911

#### 2.1

 * fixed path info to work with ‘mu-plugins’ folder, version 2.0 didn’t know how
   to find it.
 * better recognition of iPad and iPhone with iOS 4

#### 2.0

 * Added tests for iPad, iPod, Chrome, Opera
 * Added ability to test for any version for each browser
 * Added ability to get browser name and get browser version

#### 1.2

 * fixed the lesser than statements.
 * They had been looking for lesser than or equal to
 * Fixed the is_safari() statement.

#### 1.1

 * Fixed error on line 156 preventing activation

## 额外信息

 *  版本 **3.1.8**
 *  最后更新：**11 年前**
 *  活跃安装数量 **600+**
 *  已测试的最高版本为 **4.3.34**
 *  语言
 * [English (US)](https://wordpress.org/plugins/php-browser-detection/)
 * 标签
 * [browser](https://cn.wordpress.org/plugins/tags/browser/)[browser detection](https://cn.wordpress.org/plugins/tags/browser-detection/)
   [internet explorer](https://cn.wordpress.org/plugins/tags/internet-explorer/)
   [iphone](https://cn.wordpress.org/plugins/tags/iphone/)[php](https://cn.wordpress.org/plugins/tags/php/)
 *  [高级视图](https://cn.wordpress.org/plugins/php-browser-detection/advanced/)

## 评级

 4.1 星（最高 5 星）。

 *  [  10 条 5 星评价     ](https://wordpress.org/support/plugin/php-browser-detection/reviews/?filter=5)
 *  [  3 条 4 星评价     ](https://wordpress.org/support/plugin/php-browser-detection/reviews/?filter=4)
 *  [  0 条 3 星评价     ](https://wordpress.org/support/plugin/php-browser-detection/reviews/?filter=3)
 *  [  1 条 2 星评价     ](https://wordpress.org/support/plugin/php-browser-detection/reviews/?filter=2)
 *  [  2 条 1 星评价     ](https://wordpress.org/support/plugin/php-browser-detection/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/php-browser-detection/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/php-browser-detection/reviews/)

## 贡献者

 *   [ Mindshare Labs, Inc. ](https://profiles.wordpress.org/mindshare/)
 *   [ MartyThornley ](https://profiles.wordpress.org/martythornley/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/php-browser-detection/)

## 捐助

您愿意支持这个插件的发展吗?

 [ 捐助此插件 ](http://mind.sh/are/donate/)