سؤال

Is it possible to restrict a domain to only allow visitors using a specific browser?

I'm building an app and it's only been tested in Chrome so far so I only want to allow Chrome users during Beta testing. Basically, I want to white-list browsers as I go through testing. Any suggestions on the approach I should would be greatly appreciated.

هل كانت مفيدة؟

المحلول

Yes you can.

The browser that is accessing the page is in the _SERVER array.

If you find that the accessing browser is not Chrome, then just send a 404 header.

نصائح أخرى

You can block all other useragents with a relevant error message using .htaccess

Put this in .htaccess in root of your site:

ErrorDocument 503 "Your must use Chrome to access this site"
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^(Mozilla.*|Safari.*|Other.*)$ [NC]
RewriteRule .* - [R=503,L]
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top