Published in: PHP
URL: http://www.mechanicmatt.com
Using the code below, you simply include the file in your application like this:
$redirect = true; include("/www/htdocs/checkBlocked.php");
if $redirect is true, then (if the visitor is blocked), it will automatically redirect them to the URL specified in the script below. If it does not, then it simply returns a boolean true/false if the user is blocked or not (for custom processing) in a variabled called '$blocker_isBlocked'.
To add IP's and/or domains to the blacklist, just add them to the respective arrays where the commented lines are.
<?php $blocker_isBlocked_redirect = "http://www.mechanicmatt.com/Access+Denied-p71.html"; $blocker_isBlocked_return = "||{{{error}}}||"; $blocker_isBlocked_err_msg = "You have been temporarily blocked from accessing this content."; //blocking class class blocker { var $ips = NULL; var $domains = NULL; var $currentEnv = NULL; var $blocked = NULL; var $redirect = NULL; function blocker($env, $redirect = true) { //"67.191.103.115" ); //"nefec.org" ); $this->blocked = false; $this->redirect = true; } else { $this->redirect = $redirect; } $this->currentEnv = $env; } function isBlocked() { global $blocker_isBlocked_redirect; $this->checkIP(); $this->checkHostname(); if ($this->blocked == true && $this->redirect == true) { } else { return $this->blocked; } } function checkIP() { $this->blocked = true; } else { //exhaustive partial match foreach ($this->ips as $ip) { $this->blocked = true; } else { } } } } function checkHostname() { foreach ($this->domains as $k => $v) { $this->blocked = true; } else {} } } } $blocker = new blocker($_SERVER, $redirect); $blocker_isBlocked = $blocker->isBlocked(); ?>
You need to login to post a comment.
