I'm working on the CodeIgniter application where I want to split IP address into the array format. Actually, I'm getting values from the database column but unable to create the array from the dynamic values which are getting from the database?
Controller Code
Getting Values from the database
$system = $this->Xin_model->read_enter_allow_ip_address_info(1);
$allowlist = array($system[0]->enter_allow_ip_address);
$finalipallow = nl2br($allowlist);
if(!in_array($_SERVER['REMOTE_ADDR'],$finalipallow)){
$Return['error'] = 'Login Failed';
$this->output($Return);
}
Models Query
public function read_enter_allow_ip_address_info($id) {
$condition = "setting_id =" . "'" . $id . "'";
$this->db->select('enter_allow_ip_address');
$this->db->from('xin_system_setting');
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
return $query->result();
}
Dynamic Values From The Database Column
'10.0.0.1','10.0.0.2','10.0.0.3','::1'
how do I split IP address values from database into the array format like this static array
$finalipallow = array(
'10.0.0.1',
'10.0.0.2',
'10.0.0.3',
'::1'
);
I have a static array which is working with if condition
but I want to convert dynamic values into the array like the static array?
Working now here the solution of it
$system = $this->Xin_model->read_enter_allow_ip_address_info(1);
$allowlist = $system[0]->enter_allow_ip_address;
$finalipallow = str_getcsv($allowlist, ",", "'");
if(!in_array($_SERVER['REMOTE_ADDR'],$finalipallow)){
$Return['error'] = 'Login Failed';
$this->output($Return);
}