PHP Classes

File: example2.php

Recommend this page to a friend!
  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: 12 years ago
Size: 2,407 bytes


Class file image Download
// 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 /

// include the class file

$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

$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');
is_file($flag)){ $flag_img = $flag;
$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"
<title>ip2country PHP - (MySQL)</title>
<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>
  <tr><td>Country name:</td><td>
  <tr><td>2 letter code:</td><td>
  <tr><td>3 letter code:</td><td>
  <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"></font></td></tr>