From 4e44bd5b70935a1ba43f66c571a3d6ad01c33a6d Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Tue, 31 Oct 2023 10:40:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20IP=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/third_party/ip2location/controllers/index.php | 4 +++- .../third_party/ip2location/models/ip2location_db1_model.php | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) 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 ];