GnomeyNewt
06-03-2002, 03:13 PM
Is there a way to block particular browser types from visiting your website?
![]() | View Full Version : Blocking browser types GnomeyNewt 06-03-2002, 03:13 PM Is there a way to block particular browser types from visiting your website? coux 06-03-2002, 03:16 PM You can find browser detection scripts freely available everywhere. Why do you want to block them though? GnomeyNewt 06-03-2002, 03:23 PM I dont want to, but a client of mines does want to do that. I told him that he could find scripts to do it, but that would mean doing it on everypage. Which isn't that big of a deal if you just refer to the same script for everypage... But just wondering if you could in other ways....like how ip's and hostnames are blocked. Rewdog 06-03-2002, 03:31 PM I'm positive there is a way to do it, I don't know of a script that does do it though.. And i'm not a great programmer to do it. It shouldn't be too hard, post a request up in the related offers forum adn maybe you could get something.. GnomeyNewt 06-03-2002, 03:34 PM As I said, I know you can do it with a script. I've seen it done several time in Perl, JavaScript, and PHP. I guess there isn't a way to block it directly from the server itself, like blocking IP or Hostnames. bababooey 06-03-2002, 03:40 PM There isn't a way to do it Server side that I know of (at least not through a traditional server configuration setting). The only way to do it is through scripting. Comment the unneccesary lines as needed: <SCRIPT language=javascript> if (document.all) { alert("You cannot view this site with Internet Explorer."); document.location.href = "/you_are_using_ie.html"; } if (document.layers) { alert("You cannot view this site with Netscape."); document.location.href = "/you_are_using_netscape.html"; } </SCRIPT> GnomeyNewt 06-03-2002, 03:43 PM Thanks! I guess that is just wishful thinking eh? I have no idea why they would want to block a certain browser type, but it is there website. Thanks for the help. elsmore1 06-03-2002, 04:28 PM Originally posted by littlest Is there a way to block particular browser types from visiting your website? You can do what you want with an .htaccess file in the web site's root directory, using setenvif and deny directives, assuming you are running apache and have the appropriate modules loaded. See http://httpd.apache.org/docs/mod/mod_access.html#allow for an explanation of how to do it. MGCJerry 06-03-2002, 04:43 PM It is possible with an htaccess just as elsmore1 stated. I block certain "browsers" off my site, more specifically, some mass downloading software (using the mod-rewrite module). If they use a "browser" that is denied access to my site (more specifically my download folder) they get a "Page cannot be displayed" error. Here is a snippet of my .htaccess file. I got 93 other "browsers" in my list ;)... RewriteEngine on RewriteCond %{HTTP_USER_AGENT} ^.*WebZIP.*$ [OR] RewriteCond %{HTTP_USER_AGENT} ^.*FileHound.*$ RewriteRule /*$ http://about:blank [L,R] This works on both my website (*nix), and my "localhost" (win2k) website. Be careful not to remove the "http://" part of the rewriterule, cause you might get a Internal Server Error like I did ;). <edit> Oh... it looks like vB wants to put a space in between the "about:blank" part. :eek2: </edit> elsmore1 06-03-2002, 04:52 PM Rewrite rules will work too. :) It might be a little simpler, if all you are wanting to accomplish is to deny access and you don't want or need to show them anything other than an error page to just use setenvif and deny as explained in the link I provided above, while also possibly being less resource intensive for the server. (probably not an issue unless you are wanting to block MSIE 5.0+ which is probably 95% of the world) mwatkins 06-03-2002, 06:00 PM I was going to suggest the mod_access solution as well - but either that or rewrite will work. mod_access has a practical benefit in that its easier to screw up with mod_rewrite and end up with Error 500 being returned as a result. I am also guessing that resource usage is lower for the mod_access approach as well. |