I received requests from a few webmasters some time ago asking me if there was a way to block Google Chrome from their website (some websites depends on a special browser). This article shows you how you can do this in Apache or PHP.
Before you can block Google Chrome in Apache, you will need to know the "User Agent string" of Google Chrome. A typical example is:
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.23 Safari/533.4
There is a User-Agent string list for all browsers.
To block Google Chrome in Apache, we should adjust the settings in httpd.conf. If you have no permission to access httpd.conf, you can create the .htaccess in the top web directory of your site.
An example of a .htaccess file with rules to block Google Chrome is as follows:
BrowserMatchNoCase Chrome CHROME Order Deny,Allow Deny from env=CHROME
Don't forget to restart your Apache server if you modified the httpd.conf file.
Now, when you visit your website in Google Chrome, you will get a Forbidden error:
Forbidden
You don't have permission to access xxxx.htm on this server.
To block Chrome in PHP is very easy, the User-Agent string is stored in global variable $_SERVER['HTTP_USER_AGENT'], we can find the keyword "Chrome" in this variable. An example is as followers:
<?php if ( isset($_SERVER['HTTP_USER_AGENT']) ) { $t_bIsChrome = strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome'); if ( $t_bIsChrome !== false) { echo "Sorry, this website isn't compatible with Google Chrome."; exit; } } // Do something... ?>
If you have better way to block Google Chrome, please leave your comment.
Quote:
echo "Sorry, this website isn't compatible with Google Chrome.";
How to block Google Chrome