PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bogac Bokeer  >  bbIPtoCountry  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: bbIPtoCountry
Determine the country of a given IP address
Author: By
Last change:
Date: 10 years ago
Size: 1,268 bytes
 

Contents

Class file image Download
<?
   
require_once("bbIPtoCountry.class.php");
   
   
// call this script with 'update' get-variable
    // for update database from ip-to-country CSV file.
   
if ( isset($_GET['update']) )
       
UpdateDB();

   
$ip = $_GET['ip'];

   
getIPInfo($ip);
?>
<form name="iptocountry" method="get" action="<?=$_SERVER['SCRIPT_NAME']?>">
   IP Adresi: <input type="text" value="<?=$ip?>" name="ip">
</form>
<?

   
function getIPInfo($ip) {
   
        if ( empty(
$ip) ) return false;

       
$ipc = new bbIPtoCountry($ip);
       
        if ( empty(
$ipc->error) ) {
            echo
"&nbsp;&nbsp;$ipc->code2, $ipc->code3, $ipc->country<br>\n";
            echo
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$ipc->ip_from." - ".$ipc->ip_to."\n";
            echo
"<br><br>\n\n";
        }
   
        if ( !empty(
$ipc->error) )
            echo
'<br><font color="#770000">'.$ipc->error.'</font><br>';
    }
   
   
    function
UpdateDB() {

       
$ipc = new bbIPtoCountry();
       
$count = $ipc->updateDatas();

        if ( empty(
$ipc->error) ) {
           
// echo "$count items.<br>\n";
           
Header('Location: '.$_SERVER['SCRIPT_NAME']);
            exit;
        }

        echo
'<br><font color="#770000">'.$ipc->error.'</font>';
        exit;
    }
?>