<?php
/**
* @package phpIP2Country
* @author Mike Leigh
* @copyright (C) 2006 Mike Leigh. All Rights Reserved.
* @version 0.1
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
*/
/**
* phpIP2Country Main Class
*
* The main phpIP2Country class.
* @package phpIP2Country
* @access public
*/
class phpIP2Country {
var $attributes = array('status' => true);
function phpIP2Country($attributes = array()) {
if(count($attributes) >= 1) {
foreach($attributes as $key => $value) {
$this->setAttribute($key, $value);
}
}
$defaults = array();
foreach($defaults as $key => $value) {
if(!array_key_exists($key, $this->attributes)) {
$this->setAttribute($key, $value);
}
}
}
function getIPData($ipv4) {
$db = &$this->getAttribute('db');
$sql = "select * from ip2country where ip_from <= ".ip2long($ipv4)." and ip_to >= ".ip2long($ipv4);
$db->fetch($sql);
$array = $db->getResultArray();
if(count($array[0]) > 0) {
return $array[0];
}
return false;
}
function getAttribute($attribute) {
if($this->getStatus() == true) {
if(array_key_exists($attribute, $this->attributes)) {
return $this->attributes[$attribute];
} else {
$this->setStatus(false);
$this->setMessage("Attribute: '".$attribute."' does not exist");
return $this->getStatus();
}
}
}
function setAttribute($attribute, $value) {
if($this->getStatus() == true) {
$this->attributes[$attribute] = $value;
}
}
function getStatus() {
return $this->attributes['status'];
}
function setStatus($value) {
$this->attributes['status'] = $value;
}
function getMessage() {
return $this->attributes['message'];
}
function setMessage($value) {
$this->attributes['message'] = $value;
}
}
?>