PHP Classes

File: example.firewall.php

Recommend this page to a friend!
  Classes of Petter Kjelkenes   Firewall Protection   example.firewall.php   Download  
File: example.firewall.php
Role: Example script
Content type: text/plain
Description: Example usage
Class: Firewall Protection
Restrict the access to pages based on IP address
Author: By
Last change: Added support for only block/filter of certian userinput variables.
Date: 13 years ago
Size: 1,421 bytes
 

Contents

Class file image Download
<?php

// Include the class file.
include 'Firewall.php';

// Start firewall.
$firewall = new Firewall();

// Block specific ips. Also block the 20.20.x.x subnet.
$firewall->blockIP(array('84.48.167.2','20.20.20.20/255.255.0.0'));

// Only allow specific IP's..
#$firewall->allowIP('84.48.167.2');

// This removed all input, meaning you cant do anything with POST and GET actions because it gets totally stripped !!
// Normally this method is not needed to be used because it makes your script very unflexible in many cases.
#$firewall->UserInput()->preventInput();

// Remove all possible XXS and SQL injections this filters every possible input that a user can do. Notice! User may not post tags when this is used, HTML tags is removed!!
// Now you dont need to escape data later in the script, because at a highlevel this filters all the $_POST,$_GET...etc.. variables.
// Leave no arguement or false if you want to filter all global variables, (recommended). In this example we only filter post & get.
$firewall->UserInput()->inputProtection(Firewall::POST & Firewall::GET);

try{

   
// When finished setting settings you will need to run the firewall with the run() method.
   
$firewall->run();

   
$firewall->printSettings(); // For debugging only. remove this when you have checked the settings.
}catch(Exception $e){
    die(
"You are not allowed at this place.");
}




?>