Bravo List
Register
Go Back   > Bravo List > P2P > Forum > Tutorials
Reply
  #1  
Old 16th February 2010, 21:24
Phogo's Avatar
Phogo Phogo is offline
VIP
 
Join Date: Jan 2008
United Kingdom
Posts: 902
Default Block Internet Explorer from your site
Blocking MSIE from your Site

Whatever your reason, if you'd like to bar Microsoft's Internet Explorer browsers from your site, here's how you can accomplish it. Note that this could be easily made to work with (or rather, against) any other browser you chose, or against service providers, operating systems, IP addresses containing the number '7,' etc.
The ethics of the situation, and the decision, are rather complicated. My own justification is that I'm angered by the degree to which Microsoft has abused, exploited and tried to control the Internet, and if people are going to come to my proverbial electronic front door with that browser, I'm going to make them click through me griping about it first. Users of the web might have a reasonable expectation of impartial, gracefully-degraded service, but not all that plus freedom from other people's grousing.
  • CGI method -- the normal way
  • PHP method -- on servers so equipped
  • Miva Script method -- on servers so equipped
  • SSI (server-parsed HTML) method -- requires Apache 1.2 or later
  • Cold Fusion method
  • Java Server Pages method
  • JavaScript method -- when all else fails
CGI Method

This approach assumes you have the ability to put CGIs on your site, and have the filenames properly MIME-parsed for display or execution. If your ISP or server environment doesn't provide that, there are a couple other things you can try.
  1. Determine what your server looks for as the index for a page. This is almost universally index.html. Frequently other extensions (e.g. .htm, .shtml, .phtml, etc) are provided for also. Your server admin can probably tell you this if you're not sure.
  2. Make sure your server can handle a CGI as a defined file type and execute it apropriately. If not, you may need one of the more devious approaches covered later. I'll assume for this purpose that you're creating index.cgi, and that it will be properly executed.
  3. Move your existing index page (index.html or whatever) to some new filename. I suggest avoiding any of the obvious, sensible choices here -- they're easy to guess. Here, I'm going to assume you chose 'piano.shtml' as your new "homepage" filename.
  4. Create your index.cgi; here's the perl code to put in it. This could be easily done in pretty much any language you liked. Don't use shell code.
    Code:
    #!/usr/bin/perl -Tw
    
    if ($ENV{'HTTP_USER_AGENT'} &&
        $ENV{'HTTP_USER_AGENT'} =~ /MSIE|Internet Explorer/i) {
      print "Location: http://www.domain.com/ie_reject.shtml\n\n";
    } else {
      print "Location: http://www.domain.com/piano.shtml\n\n";
    }
    exit;
  5. Adjust the bits to fit your site. The /usr/bin/perl part will vary quite a bit between systems, and the URLs should be edited to fit. You don't inherently need the fully qualified URL -- just /filename.html is probably adequate.
  6. Make it world-executable. On most unices, 'chmod +x index.cgi' will accomplish this.
  7. Create your 'reject' file -- the HTML file that MSIE users should see in place of your actual homepage. Here, that's ie_reject.shtml. My suggestion is that you be polite -- it's the browser you're rejecting (presumably), not the user, and the company (Microsoft) that you object to, not the person with the product. They may be extreme novices and not know anything about other browsers, or forced to use MSIE one way or another despite that they might prefer something else. If that doesn't apply, say whatever you bloody well please. Keep in mind also that you can put your email address on the reject page for people to send their comments, but if you do so you will also get a lot of derisive and grammatically dubious mail from IE users who were just given a pithy lecture about their choice of browsers.
  8. Adjust links on your site, if you so desire. You should never link to the default index page anyway -- if you want to link to an index.html in a given directory, use the name of the directory. As such, assuming you were linking to /index.shtml, change it to either / or /piano.shtml. If you use /, you'll be re-running the script every time, which is a bit more secure concerning IE users entering the site without going to /, but also a little harder on the server.
  9. Check it out, and fix any problems. A lot of diferent things can go wrong here, but the biggest one is that index.cgi isn't being executed, for whatever reason. If you need help, contact your sysadmin or whomever seems apropriate.
CGI method variants:

  • First, if you don't have the option to have a CGI executed as the index file for a page, but do have the option to use CGI space located elsewhere, you can use a normal /cgi-bin/-placed CGI instead. To try that, put this in as your /index.html:
    Code:
    <meta http-equiv="refresh" content="0;
    url=http://www.domain.net/cgi-bin/index.cgi">
    Then take the code for index.cgi above and put that in /cgi-bin/index.cgi.
  • If you don't have a CGI space available, but can use server-parsed HTML (.shtml, .phtml, etc) and can have your own programs executed by '#include cmd' (or #include cgi) commands, then put this in /index.shtml:
    Code:
    <meta http-requiv="refresh" content="0;
    url="<!--#include cmd="index.cgi"-->">
PHP Method

This works very well on web servers capable of using PHP scripting code. It has the added advantage that it doesn't require CGI execution or redirection, and can't be circumvented by knowing the URL for the "real" page. It's pretty simple, actually. Place this code at or near the top of your code, before any output has occurred.
PHP Code:
 <?php
   
if (preg_match("/MSIE/",getenv("HTTP_USER_AGENT")) ||
       
preg_match("/Internet Explorer/",getenv("HTTP_USER_AGENT"))) {
    
header("Location: http://www.domain.com/ie_reject.html");
    exit();
   }
Update: this is known to work with PHP3 and beta versions of PHP4.
Miva Script Method

This was contributed by Eric Sechrist <newwave/atnewwave.primeline.\moc>. Haven't tried it myself, but the product page for it indicates that Miva is a server-side scripting language with a respectable supported platforms list.
Place this code at the top of your index.mv file, and adjust 'reject.txt' to whatever file you prefer (presumably including HTML):
Code:
<MvIF EXPR = "{ 'msie' CIN http_user_agent }">
<MvDO FILE = "reject.txt">
<MvEXIT>
</MvIF>
ColdFusion Method

This approach works with Macromedia's ColdFusion server-side application environment (formerly from Allaire). Contributed by Justin Felker.
Code:
<CFIF findNoCase("msie", cgi.http_user_agent)>
    <CFLOCATION url="ie_reject.html" addtoken="no">
<CFELSE>
    <CFLOCATION url="real_page.html" addtoken="no">
</CFIF>
JSP Method

Also from Justin Felker: this approach works with Sun's Java Server Pages (JSP).
Code:
<%
if (request.getHeader("User-Agent").toLowerCase().indexOf("msie") != -1)
    response.sendRedirect("ie_reject.html");
else
    response.sendRedirect("real_page.html");
%>
SSI Method

This approach employs the flow control element capability in the wonderful Apache webserver, v1.2 and later. As of this writing, more than half the webservers on the net run Apache, including a large percentage of ISPs and hosting agencies. To find out if you can use this method, telnet to port 80 of the webserver and enter "HEAD / HTTP/1.0", then press enter twice; look through the resulting headers for the "Server:" header, which should contain the server name and version. Microsoft's IIS webserver may support some feature like this also, but chances are if you're running IIS you aren't likely to employ this whole procedure anyway. Documentation on Apache's mod_include SSI module can be found here.
As above, move your "real" entry page to another file (realhomepage.html assumed here), create your IE rejection file (reject.html assumed). You'll generally need to create your index file as index.shtml instead of .html; this may vary between webservers. Be sure that index.shtml is the only "index" file present, as many webservers will prefer .html and/or .htm files over .shtml in the selection order.
Code:
<!--#if expr="$HTTP_USER_AGENT = /MSIE/" -->
<!--#include virtual="reject.html" -->
<!--#elif expr="$HTTP_USER_AGENT = /Internet Explorer/" -->
<!--#include virtual="reject.html" -->
<!--#else -->
<!--#include virtual="realhomepage.html" -->
<!--#endif -->
This approach has the advantage of working on a large portion of webservers; however, it does not prevent loading the "real" page via MSIE via some other path (search engine referral, etc).
JavaScript Method

This is a good fallback if you aren't able to use any server-executed code. It has the benefit of being fairly difficult to defeat, since it works on the browser's appName property, which is usually hardcoded into the browser and is difficult to change. The disadvantages are that, first, it will annoy users of browsers that don't use javascript; second, it will permit entry by MSIE users when they have JavaScript disabled. The <meta> redirect will attempt to cope with browsers that don't support or aren't configured to use JS.
  1. Move your index.html file to another filename as above.
  2. Place the following in a new index.html file:
    Code:
    <html>
    <head>
            <meta http-equiv="refresh" content="1; 
    URL=http://www.domain.com/realhomepage.html">
    </head>
    <body>
    <script language="javascript">
    <!--
    if (navigator.appName == "Microsoft Internet Explorer") {
            document.location = "http://www.domain.com/ie_reject.shtml"; 
    } else { 
            document.location = "http://www.domain.com/realhomepage.html";
    }
    // -->
    </script>
    </body>
    </html>
  3. Adjust the URLs accordingly.
Reply With Quote
  #2  
Old 16th February 2010, 21:36
joeroberts's Avatar
joeroberts joeroberts is offline
BT.Manager Owner
 
Join Date: Jan 2008
United States
Posts: 2,113
Default
the php one should be like this for php5.3+
PHP Code:
<?php
   
if (preg_match("/MSIE/",getenv("HTTP_USER_AGENT")) ||
       
preg_match("/Internet Explorer/",getenv("HTTP_USER_AGENT"))) {
    
header("Location: http://www.domain.com/ie_reject.html");
    exit();
   }
__________________
Do not ask me to help you work on your site that is not phpMyBitTorrent
Do not ask me to make a mod for any other source
Do not Ask me to setup your site.
I will no longer help you setup your site, there is a setup script if you have trouble with it post in the forum here or in BT.Manager™ forum
My Current Demo is here http://demo.btmanager.org/
Reply With Quote
The Following 2 Users Say Thank You to joeroberts For This Useful Post:
papad (12th May 2020), Phogo (16th February 2010)
  #3  
Old 16th February 2010, 21:39
Phogo's Avatar
Phogo Phogo is offline
VIP
 
Join Date: Jan 2008
United Kingdom
Posts: 902
Default
Updated, thanks Joe
Reply With Quote
  #4  
Old 30th August 2010, 22:30
Phogo's Avatar
Phogo Phogo is offline
VIP
 
Join Date: Jan 2008
United Kingdom
Posts: 902
Default Blocking MSIE from your Site
PHP Code:
<?php
   
if (eregi("MSIE",getenv("HTTP_USER_AGENT")) ||
       
eregi("Internet Explorer",getenv("HTTP_USER_AGENT"))) {
    
Header("Location: http://www.domain.com/ie_reject.html");
    exit;
   }
?>
or
HTML Code:
<html>
<head>
        <meta http-equiv="refresh" content="1; 
URL=http://www.domain.com/realhomepage.html">
</head>
<body>
<script language="javascript">
<!--
if (navigator.appName == "Microsoft Internet Explorer") {
        document.location = "http://www.domain.com/ie_reject.shtml"; 
} else { 
        document.location = "http://www.domain.com/realhomepage.html";
}
// -->
</script>
</body></html>
Reply With Quote
Reply

Tags
block , explorer , internet , site

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is YOUR Internet Speed? dopeboy Community Cafe 11 2nd February 2010 20:59
how to behave on an internet forum Subzero Community Cafe 3 11th July 2009 07:50
Download blocking [TSSE 5.1] Omen Template Shares 2 13th September 2008 19:06
What is your internet connection ? Fynnon Community Cafe 1 13th June 2008 19:50
Free - Internet Security (Complete Solutions ) dadix Community Cafe 0 9th March 2008 14:13



All times are GMT +2. The time now is 10:59. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.