diff --git a/application/third_party/ip2location/controllers/index.php b/application/third_party/ip2location/controllers/index.php index 5379991f..7d7ec2d3 100644 --- a/application/third_party/ip2location/controllers/index.php +++ b/application/third_party/ip2location/controllers/index.php @@ -31,7 +31,9 @@ class Index extends CI_Controller if (empty($data['ip_address'])) { $data['ip_address'] = $this->input->ip_address(); } - $country = $this->Ip2location_db1_model->get_country_by_ip($data['ip_address']); + $ip_number = $this->Dot2LongIP($ip_address); + $country = $this->Ip2location_db1_model->get_country_by_ip($ip_number); + $country['ip_address'] = $data['ip_address']; echo json_encode($data); } diff --git a/application/third_party/ip2location/models/ip2location_db1_model.php b/application/third_party/ip2location/models/ip2location_db1_model.php index bab48b89..23056bad 100644 --- a/application/third_party/ip2location/models/ip2location_db1_model.php +++ b/application/third_party/ip2location/models/ip2location_db1_model.php @@ -13,14 +13,14 @@ class Ip2location_db1_model extends CI_Model } - public function get_country_by_ip($ip_address) + public function get_country_by_ip($ip_number) { $sql = " SELECT TOP 1 ipdb.country_code, ipdb.country_name FROM ip2location_db1 ipdb WHERE ? BETWEEN ipdb.ip_from AND ipdb.ip_to "; - $query = $this->INFO->query($sql, array($ip_address)); + $query = $this->INFO->query($sql, array($ip_number)); $country = array( 'country_code' => '', @@ -30,7 +30,6 @@ class Ip2location_db1_model extends CI_Model if ($query->num_rows() > 0) { $row = $query->row(); $country = [ - 'ip_address' => $ip_address, 'country_code' => $row->country_code, 'country_name' => $row->country_name ];