1

For my website running on Wordpress, I want to block readers accessing it from UC Browser.. I have come across some scripts that can block the usual suspects (Chrome, Firefox, Safari, etc.). Is there a way I can detect UC Browser and block access via it?

Here are the details of UC Browser's User Agent:

  1. http://www.whatsmybrowser.org/b/434TWLW
  2. http://bit.ly/1YlL8fW

How can this be done?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
  • 1
    Have you searched "block user agent"? See http://www.inmotionhosting.com/support/website/security/block-unwanted-users-from-your-site-using-htaccess – Michał Perłakowski Dec 18 '15 at 07:58
  • Yep.. I did check it.. But not very sure of how do I use it, esp. for my use-case.. Also I was looking at using this WP plugin to get the job done but it supports FF, Chrome, Safari, IE and Opera only.. https://wordpress.org/plugins/advanced-browser-check/ Any suggestions to block access to UC Browser and show a pop-up / warning? – Shalin Tejpal Jain Dec 18 '15 at 08:33
  • Does your server support .htaccess? – Michał Perłakowski Dec 18 '15 at 08:37

3 Answers3

1

Use following .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*UCBrowser.*$ [NC]
RewriteRule .* - [F,L]

It will block any browser which send User-Agent header containing string UCBrowser.

If you want to redirect all UCBrowser users to specific page, for example showing information that this browser is not supported, your .htaccess should look like this:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*UCBrowser.*$ [NC]
RewriteRule .* browser-not-supported.html [L]
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
  • Thanks @gothdo. Will try it out. It will be very helpful if you can guide me on how do I show a responsive pop-up to UC Browser users asking them to try some other browser when this block thing works (let's say chrome)... Something like this: https://www.dropbox.com/s/j35o9yxtaudk9qw/screengrab-browser-check-pop-up.jpg?dl=0 – Shalin Tejpal Jain Dec 18 '15 at 09:05
  • 1
    Would have definitely loved to do that.. Unfortunately, my reputation on SO is still lesser than 15 (don't access it frequently but would that's something that I do intend to change). So, unable to upvote for now but have accepted your answer.. Thanks once again... – Shalin Tejpal Jain Dec 18 '15 at 15:47
  • You can't rely only on the string "UCBrowser" as in the answer! There are variants out there in the wild with "UC Browser" http://ua.theafh.net/list.php?s=%22UC+Browser%22&include=yes&class=all&do=desc and also with the string "UCWEB" http://ua.theafh.net/list.php?s=%22UCWEB%22&include=yes&class=all&do=desc And they don't necessarily come together, so you have to test all three to get all variants of UC Browser... – theafh Jan 07 '16 at 11:42
  • How about nginx ? Do you have some example – Robbi Nespu Nov 24 '16 at 18:33
  • @RobbNesp I think you should ask a new question about that. – Michał Perłakowski Nov 24 '16 at 19:04
  • After all searching i found this is the only answer which approved . I am looking for How can we block only moblie UC users not entire users (or) block from a specific resolution like <480px etc.. – Imran Mohammed Jan 05 '17 at 06:06
1

Please Try this, this script will blocked old and latest all UCBrowser and redirect to custom page

RewriteCond %{HTTP_USER_AGENT} ^.*UBrowser.*$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^.*UCBrowser.*$ [NC]
RewriteRule .* browser-not-supported.html [L]
Jon Clements
  • 138,671
  • 33
  • 247
  • 280
  • I tried this. www.xyz.com gets the necessary block. But www.xyz.com.a.html opens easily. What to do in this case? – Nikhil Mar 06 '20 at 15:56
0

It is somewhat "simple", but not "too simple".

You may detect the browser using JavaScript Window Navigator. The window.navigator object contains information about the visitor's browser.

Refer here http://www.w3schools.com/js/js_window_navigator.asp and you will find a demo here https://jsfiddle.net/wvbdnb8o/ which detects some common browsers using some code like;

var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

Next, create a "mask" using html and css. I mean, A full screen, opaque <div>, that prevent readers from viewing the contents of page. You may refer this stackoverflow post How to make a <div> always full screen?.

When you detect UC Browser, display the mask, else, hide it. Hope this will give you a kick start.

Alfred
  • 21,058
  • 61
  • 167
  • 249