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 Dwayne Rothe  >  IP2Country PHP  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Example
Class: IP2Country PHP
Get information of the country of an IP address
Author: By
Last change: typo
Date: 2010-11-22 15:40
Size: 2,407 bytes
 

Contents

Class file image Download
<?PHP
// example of use with form input

// set directory path to where the ip2countryphp.sql.php file is
// this MUST be a relative path and MUST include the end slash /
define("BASEDIR","./"); 

// include the class file
include(BASEDIR."ip2countryphp.sql.php"); 

$ip_address null;
$two_letter_code null;
$three_letter_code null;
$country_name null;
$flag_img = (BASEDIR.'flags/blank.gif');
$flag_width "0";

// get ip info when form is submitted
if(isset($_POST['ipinfo'])){

  
$ip_post trim(strip_tags($_POST['ipinfo']));
  
$ip_address long2ip(ip2long($ip_post));
  
  
// get 2 and 3 letter counrty codes and country name.
  
$two_letter_code   $ip->country_code($ip_address'cc2l');
  
$three_letter_code $ip->country_code($ip_address'cc3l');
  
$country_name      $ip->country_code($ip_address'country');
  
$flag_width "30";
  
  
// if country code is known get countries flag else use blank image.
  
$flag = (BASEDIR.'flags/'.strtolower($two_letter_code).'.gif');
  if(
is_file($flag)){ $flag_img $flag;
  }
  else{
$flag_img = (BASEDIR.'flags/blank.gif'); $flag_width ='0';}
}
// print the form and results to the webpage
print <<<TEST
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ip2country PHP - (MySQL)</title>
</head>
<body style="font:normal 9pt tahoma,arial,verdana">
<form method="POST">
<table style="margin-top:20px;border:#CCCCCC 1px solid" width="280" cellspacing="2" cellpadding="3" border="0" align="center">
  <tr><td bgcolor="#CCCCCC" colspan="2">&nbsp;<font color="white">ip2country PHP (MySQL)</font></td></tr>
  <tr><td>Enter ip:</td><td><input type="field" name="ipinfo" style="width:90px" maxlength="15"></td></tr>
  <tr><td width="120" height="26">IP Address:</td><td>
$ip_address</td></tr>
  <tr><td>Country name:</td><td>
$country_name</td></tr>
  <tr><td>2 letter code:</td><td>
$two_letter_code</td></tr>
  <tr><td>3 letter code:</td><td>
$three_letter_code</td></tr>
  <tr><td>Country flag:</td><td><img src="
$flag_img" width="$flag_width" border="0"></td></tr>
  <tr><td colspan="2" align="right"><input type="submit" value="Submit">&nbsp;</td></tr>
  <tr><td bgcolor="#CCCCCC" colspan="2"><font color="white" size="1">www.ip2countryphp.freei.me</font></td></tr>
</table>
</form>
</body>
</html>
TEST;
exit;
?>