PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of Robert Mahan  >  PHP Block IP Range  >  readme.txt  >  Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: Documentation
Class: PHP Block IP Range
Check if IP is in a blacklist or a whitelist
Author: By
Last change: Added IPv6 support to class
Date: 6 years ago
Size: 3,084 bytes



Class file image Download
PHP IpBlockList

Author:		Robert Mahan


	filename1 = 'whitelist filename';
	filename2 = 'blacklist filename';

	$list = new IpBlockList( filename1, filename2 );
	$ip = 'a.b.c.d';
	boolean $result = $list->ipPass( $ip );
	$msg = $list->message();

	This class reads in files containing a list of addresses/address ranges to
	be whitelisted and/or blacklisted.  The filenames may be specified at the
	creation of the IpBlockList Object.  If they are not specified, default
	filenames of '_whitelist.dat' and '_blacklist.dat' will be used.  The 
	ip addresses may be specifed in the files as single ip addresses or a range
	of ip addresses, one value per line.  The files may contain comment lines
	or inline comments beginning with '#', and blank lines for readability.
	See the included example '_whitelist.dat' and '_blacklist.dat' files.
	The whitelist should include ip addresses that should not be blocked, the
	blacklist should contain ip addresses to be blocked. The whitelist is 
	checked first and will overide the blacklist ip addresses.
	If an ip address is found in the whitelist file, the function ipPass() will
	immediately abort the check and return a value of True. If an ip address is 
	found in he blacklist file, the function ipPass() will return False.  If the
	ip address is not found in either the whitelist or the blacklist files, the
	function ipPass() will return the value True.
	After the function ipPass() completes a result message may be retrieved using
	the function message().

Whitelist/Blacklist file Format:

  IPv4 Addresses:
	ipaddress (single):

	ipaddress/netmask (CIDR):
  IPv6 Addresses:
    ipaddress (single):
    ipaddress/netmask (CIDR){
	Read the example files for more details.

Class Methods:

    boolean IpBlockList::ipPass( string ipaddress )
        Returns true or false.  If found in the 'whitelist' or
        not found in either list true is returned.  If found
        in the 'blacklist' list false is returned.
    string IpBlockList::message() 
        Returns a string describing the reason for the results of
        the check. Is valid following a call to ipPass().  This
        is useful for logging results.
    integer IpBlockList::status()
        Returns an integer showing the status of the last call to
        ipPass(). Returns 1 if the ipaddress was found in the whitelist,
        -1 if the ipaddress was found in the blacklist, and 0 if not 
        found in either list.