I am trying to have a login function in codeigniter model, but cannot retrieve cookies there.
It returns bool false.
I have tried searching for the problem,one of the problem was cookies were not being set, but my cookies are being set in the browser, under domain localhost. And I have tried using cookies on localhost earlier in a different project, without codeigniter, in which I was able to retrieve cookies on localhost.
Here $_COOKIE['username']
would throw error invalid index 'username', $this->input->cookie('username')
would return bool(false)
. But I can see 'username' cookie in my browser.
Cookies set and retrieved are on different files.
public function checkLogin(){
$this->load->helper('cookie');
$row['user'] = $this->input->cookie('username', TRUE);
$row['handle'] = $this->input->cookie('email', TRUE);
$row['id'] = $this->input->cookie('pid', TRUE);
$row['type'] = $this->input->cookie('type', TRUE);
$row['slug'] = $this->input->cookie('slug', TRUE);
$row['cuid'] = $this->input->cookie('cuid', TRUE);
return $this->input->cookie('username', false);
}
}
I set the cookies in a different file,
setcookie("username",$user, time()+60*60*60*24*30);
setcookie("email",$handle, time()+60*60*60*24*30);
setcookie("pid",$row['id'], time()+60*60*24*30*60);
setcookie("type",$type, time()+60*60*24*30*60);
setcookie("slug",$row['slug'], time()+60*60*24*30*60);
setcookie("city",$row['city'], time()+60*60*24*60*30);
setcookie("cuid", $code, time()+60*60*24*60*30);
Please ask for more information needed. I have used construct function(two underscores) in my controller, not in model. The form where cookies are being set is not in controller or model but in root folder. And I have tried setting cookies using $this->input->set_cookie();
too.