Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Where can I get code to block certain Web browsers from accessing my web site?
I would like to block web users on Netscape Navigator from accessing my Web site. (I've seen web pages that have a "your browser is not supporter" block). Where can I get that code and/or how do I set it up?
4 Answers
- E.M.BedLv 51 decade agoFavorite Answer
The best way to do this is in your server script - that way users cannot bypass your javascript by switching javascript off.
The environment variable HTTP_USER_AGENT can be used in your script to detect the browser and you can return whatever page you like with no need for redirection.
This is example PHP of browser detection:
<?php
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko') )
{
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Netscape') )
{
$browser = 'Netscape (Gecko/Netscape)';
}
else if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Firefox') )
{
$browser = 'Mozilla Firefox (Gecko/Firefox)';
}
else
{
$browser = 'Mozilla (Gecko/Mozilla)';
}
}
else if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE') )
{
if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera') )
{
$browser = 'Opera (MSIE/Opera/Compatible)';
}
else
{
$browser = 'Internet Explorer (MSIE/Compatible)';
}
}
else
{
$browser = 'Others browsers';
}
echo $browser;
?>
- Taurus Fan...Lv 41 decade ago
I am assuming that you are a techie.
Typically, you can do this using JavaScript in your HTML code. So when the browser attempts to render the page the JavaScript will kick in and block the user -- you may also have to include redirect to ensure that the user is always directed away from your website, in the event that the browser is not a desirable one.
Remember though, though you can't really "block" the user, unless you are using a lower level language such as C#.net or Java.
- ChipChampLv 41 decade ago
Check this out for information on it:
http://w3schools.com/htmldom/prop_nav_appname.asp
You would have to do an if or switch statement in JavaScript sort of like this:
<script type="text/javascript">
if (navigator.appName == "Netscape") {
document.write("Your browser is not supported.");
}
else {
document.write("Your code here....");
}
</script>
- ?Lv 45 years ago
in the journey that your internet host helps lively server pages ( ASP ) you ought to use <%Browser=Request.ServerVariables (HTTP_USER_AGENT)%> then block it by using <% If Browser = internet Explorer Then ' do not something Else reaction.Write "Browser not supported, sorry" end If %>