Login   Register  
PHP Classes
elePHPant
Icontem

File: Examples/ipfunctions.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Volkan Küçükçakar  >  XIP Class  >  Examples/ipfunctions.php  >  Download  
File: Examples/ipfunctions.php
Role: Example script
Content type: text/plain
Description: Example 2 - IP Functions, IP validate, public/private IP check, network check, local blacklist
Class: XIP Class
Analyze remote IP, Proxy detection,Blacklist check
Author: By
Last change: -Bug Fixed in IP octet pattern -Added Example 3: Blacklist (Local) - Another local blacklist example using an external flat text file -Added Example 4: IP Log - IP Log example using a flat text file (with exclusive file lock support via flock and semaphore files) -Added Example 5: Blacklist (Check RBL) - Checking the existance of visitor's IP in RBL (Real-Time Blackhole List) using 3rd party services
Date: 8 years ago
Size: 4,963 bytes
 

Contents

Class file image Download
<?
/**
 XIP Class - Proxy Detection and IP Functions class for PHP - File Name: ipfunctions.php
 Copyright (C) 2004-2006 Volkan Küçükçakar. All Rights Reserved.
 (Volkan Kucukcakar)
 http://www.developera.com

 You are requested to retain this copyright notice in order to use
 this software.

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the  Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
?>
<?     
/*
       XIP Class - EXAMPLE 2 - ipfunctions.php
       This example demonstrates:
       IP Functions, IP validate, public/private IP check, network check, local blacklist
       */
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<title>XIP Class - developera.com/xip</title>
<body bgcolor="#FFFFFF" text="#000000">
<center>
<p><a href="proxydetect.php">Proxy Detection</a> | IP Functions | <a href="blacklist_local.php">Blacklist (Local)</a> | <a href="iplog.php">IP Log</a> | <a href="CheckRBL.php">Blacklist (Check RBL)</a></p>
<p align="left"><font color="#FF6666">XIP Class - EXAMPLE 2 - ipfunctions.php - </font><font color="#707070"> IP Functions, IP validate, public/private IP check, network check, local blacklist </font></p>
<p>&nbsp; </p>
  <table width="600" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td width="300">Your Client IP is </td>
      <td width="300">&nbsp;

<?
   
require('../class.XIP.php');
   
$XIP=new XIP();
   echo 
$XIP->IP['client'];
?>

      </td>
    </tr>
    <tr>
      <td>is Client IP in blacklist? </td>
      <td>&nbsp;
<?
    $blacklist
=!(empty($_POST['t_blacklist'])) ? $_POST['t_blacklist'] : "10.0.5.0\r\n10.0.4.0/24\r\n10.0.3.0/255.255.255.0";
    if (
$XIP->CheckNet($blacklist)) {echo "YES";} else {echo "NO";}
?>

      </td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <table width="600" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td width="300">Test IP is </td>
      <td width="300">&nbsp;
<?
   $test_ip
=!(empty($_POST['t_ip'])) ? $_POST['t_ip'] : $XIP->IP['client'];
   echo 
$test_ip;
?>

      </td>
    </tr>
    <tr>
      <td>is Test IP Valid ? </td>
      <td>&nbsp;
<?
    
if ($XIP->isValid($test_ip)) {echo "YES";} else {echo "NO";}
?>

      </td>
    </tr>
    <tr>
      <td>is Test IP Public or Private(local) ? </td>
      <td>&nbsp;
<?
    
//if ($_POST['priv_ip_list']=="extended") $XIP->ex_private=true;
    
if (array_key_exists('priv_ip_list',$_POST)&&($_POST['priv_ip_list']=="extended")) $XIP->ex_private=true;
    if (
$XIP->isValid($test_ip)){
         if (
$XIP->isPublic($test_ip)) {echo "Public IP";} else {echo "Private IP (local)";}
    }
?>

      </td>
    </tr>
    <tr>
      <td>is Test IP in blacklist? </td>
      <td>&nbsp;

<?
    
if ($XIP->CheckNet($blacklist,$test_ip)) {echo "YES";} else {echo "NO";}
?>

      </td>
    </tr>
    <tr>
      <td>Test IP belongs to given network? </td>
      <td>&nbsp;
<?
    $network
=!(empty($_POST['t_network'])) ? $_POST['t_network'] : "192.168.0.0/16\r\n10.0.0.2";
    if (
$XIP->CheckNet($network,$test_ip)) {echo "YES";} else {echo "NO";}
?>

      </td>
    </tr>
  </table><br><br>
  <form name="form1" method="post" action="">
    <p>Test IP:
      <input type="text" name="t_ip" value="<? echo $test_ip?>" size="32" maxlength="15">
</p>
    <p>Normal Private IP List
      <input name="priv_ip_list" type="radio" value="normal" checked>
      <input name="priv_ip_list" type="radio" value="extended">
Extended Private IP List:   </p>
    <p>BLACKLIST:
      <textarea name="t_blacklist" cols="32" rows="4" id="t_blacklist">
<? echo $blacklist?>
</textarea>
    </p>
    <p>Network:
      <textarea name="t_network" cols="32" rows="4" id="t_network">
<? echo $network?>
</textarea>
</p>
    <p>
      <input type="submit" name="Submit" value="Test IP">
</p>
  </form>
  <p>&nbsp;</p>
  <p><strong>XIP Class<br>
    </strong>Proxy Detection and IP Functions class for PHP<strong><br>
  </strong><a href="http://www.developera.com/xip">www.developera.com/xip</a></p>
  <p>&nbsp; </p>
</center>
</body>
</html>