Location: PHPKode > scripts > Firewall > firewall/example.php
<?php 
include 'firewall.class.php';
/****************************************************************************************
*   Class   :   firewall
*   Ver.    :   1.0
*   Author  :   Temperini Mirko  <hide@address.com>
*   Date    :   03-30-2010
*   License :   GPL License
*
*   IMPORTANT!!!
*   The firewall must be EVER started at the top of  the script ( think to session_start() as condition rules) 
*
*   ONLY ONE ISTANCE IS ALLOWED IN A PAGE!!! 
*   
* 
*   calling costructor, you can pass directly the rules table to parse
*   es: $myFirewall = new firewall(fielname.ext);
*   and the table is directly loaded
*
*
*
*   you can set 2 different types of output on deny ip:
*   default:     send an header with 403 Status (Forbidden)
*   redirect:    it redirect by a single javascript line to a link specified.
*               why javascript? because when a server is not propelry setted or the page have already sended the header, it not fail.  
*               $myFirewall->setAction('redirect','http://www.google.com');
*
*   show:       simply output the code you pass in 
*               $myFirewall->setAction( 'show',file_get_contents('forbidden.tpl') );
*
*
*   if no action is specified, the default is a blank page whit 403 Status Header (Forbidden)
*
*
*   ok, we turn On our firewall
*   $myFirewall->start();
*   
*
*
*   this class is successfull tested on PHP 5.3 
*
*   please report bugs at : <hide@address.com>
*   
****************************************************************************************/




/*
//EXEMPLE 1
//call firewall passing the table rules
$myFirewall = new firewall('rules.table'); 
//set action to redirect on Google.com 
$myFirewall->setAction('redirect','http://www.google.com');
//start up the firewall
$myFirewall->start();
*/

/***************************************************************/
//EXEMPLE 2
//call firewall
$myFirewall = new firewall; 

//set if must try to resolve ip from hostname. This feature is not available for an ip range rule.
//CAUTION! 
//this feature can make your firewall slow! Depends from the necessary time to resolve the IP!
//$myFirewall -> forceHostname(true);   

//load the rules table
$myFirewall->loadTable('rules.table');


$myFirewall->onAllow('allowed_callback');


function allowed_callback($ip){
    echo "<br />HI, I'm a callback, and I know that your ip is $ip<br />";
    }

//set action to redirect on Google.com 
$myFirewall->setAction('show',file_get_contents('forbidden.tpl'));

//start up the firewall
$myFirewall->start();
/***************************************************************/



// if samething is wrong you can see this message
echo "i'm showed!!!<br />";
?>
Return current item: Firewall