I'm having some trouble handling cookies. Initially I have set the cookie value to 0. When a user navigates to next page, I want to increment the cookie value by one. My controller is like this:
class Welcome extends CI_Controller {
public function index() {
$this->load->helper('cookie');
$this->input->set_cookie("starttime", time(),time()+3600);
$this->input->set_cookie("pagevisited",0,time()+3600);
$_SESSION['currenttime'] = time();
$this->load->view('indexpage');
}
public function page1() {
$this->load->helper('cookie');
$value = $this->input->cookie("pagevisited");
$this->input->set_cookie("pagevisited",$value+1,time()+3600);
$this->load->view('page1');
}
public function page2() {
$this->load->helper('cookie');
$value = $this->input->cookie("pagevisited");
$this->input->set_cookie("pagevisited",$value+1,time()+3600);
$this->load->view('page2');
}
}
The above code is not working. The cookie value is still 0. I noticed that CI is also storing session variables with the same cookie name.