Login   Register  
PHP Classes
elePHPant
Icontem

File: Example2.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Robert Mahan  >  PHP Block IP Range  >  Example2.php  >  Download  
File: Example2.php
Role: Example script
Content type: text/plain
Description: Example testing IPs
Class: PHP Block IP Range
Check if IP is in a blacklist or a whitelist
Author: By
Last change:
Date: 1 year ago
Size: 800 bytes
 

Contents

Class file image Download
<?php

include_once( 'ipblocklist.class.php' );

$ips = array(   '192.168.1.0',
                 
'192.168.1.1',
                 
'192.168.1.2',
                 
'127.0.0.1',
                 
'200.0.0.10',
                 
'256.128.64.32' );

$ip1 = new IPObj('192.168.1.1');

foreach( 
$ips as $ip ) {
    try {
        
$ip2 = new IPObj$ip );

        switch( 
$ip1->_Cmp$ip2 ) ) {
        case -
1:
            
$op ' < ';
            break;
        case 
0:
            
$op ' == ';
            break;
        case 
1:
            
$op ' > ';
            break;
        default:
            
$op ' ? ';
            break;
        }
        print( 
$ip1.$op.$ip2.'<br/>');
    }
    catch( 
Exception $e ) {
        echo 
$e->getMessage() . '<br/>';
    }
}

?>