修改 IP 查询出错

master
Jimmy Liow 2 years ago
parent f0c634d361
commit 4e44bd5b70

@ -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);
}

@ -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
];

Loading…
Cancel
Save