PhpSnip.com

User Stats

UA Blocker ( PHP Version )

UA Blocker allows you to selectively deny specific user-agents from visiting your site. This helps to eliminate email harvesting, and various other bandwidth-sucking visitors. Some examples are included.

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 547

Source Code ( 65 lines )

<?php

//UA BLOCK
//By: Christopher Lover - webmaster@icehousedesigns.com
//http://www.icehousedesigns.com
//This script is freeware. I accept no responsibility for damage it may cause (which should be none).
//This script can be freely modified, as long as this header is included.
// Place <?php include ("/path/to/block.php3"); ?> at the TOP of your HTML documents



//List user-agents below you wish to ban in correct format




        $browser = array ("Wget", "EmailSiphon", "WebZIP","MSProxy/2.0","EmailWolf","webbandit","MS FrontPage");

        $punish = 0;
        while (list ($key, $val) = each ($browser)) {
                if (strstr ($HTTP_USER_AGENT, $val)) {
                        $punish = 1;
                }
        }
//Be sure to edit the e-mail address and custom page info below

        if ($punish) {
                // Email the webmaster
                $msg .= "The following session generated banned browser agent errors:n";
                $msg .= "Host: $REMOTE_ADDRn";
                $msg .= "Agent: $HTTP_USER_AGENTn";
                $msg .= "Referrer: $HTTP_REFERERn";
                $msg .= "Document: $SERVER_NAME" . $REQUEST_URI . "n";
                $headers .= "X-Priority: 1n";
                $headers .= "From: Ban_Bot <bot@yourdomain.com>n";
                $headers .= "X-Sender: <bot@yourdomain.com>n";

                mail ("webmaster@yourdomain.com", "BANNED BROWSER AGENT ERROR", $msg, $headers
        

);
        
                // Print custom page
                echo "<HTML>
                      <head>
                      <title>Access Denied</title>

                      </head>

        
                      <p>We're sorry. The software you are using to access our website is not allowed.
                         Some examples of this are e-mail harvesting programs and programs that will
                         copy websites to your hard drive. If you feel you have gotten this message
                         in error, please send an e-mail addressed to admin. Your I.P. address has been logged
                         Thanks.</p>
                         <BR>
                         -Yourname
                         <BR>
                         </body>

                         </HTML>";
                exit;
        }
  
?>

Search

Subscribe

  Rss Feeds

Sponsors

Advertise