I am using codeigniter and in my library file I am storing the cookie that works fine whenever browser is opened, but expires when I close the browser is any thing is wrong in code?
$this->CI =& get_instance();
$this->CI->load->helper('cookie');
$expire = time()+(60*60*24*30);
$cookie = array(
'name' => 'username',
'value' => $users['username'],
'expire' => $expire
);
$this->CI->input->set_cookie($cookie);
$cookie = array(
'name' => 'password',
'value' => $users['password'],
'expire' => $expire
);
$this->CI->input->set_cookie($cookie);
The problem is the expiration time you are sending … this is from the help page here
So change your code to this :
To set the cookie to expire 30 days from now
(Although setting it like you did should probably have worked – but the expiration would be years in advance … the help document also shows the expiration given as a string – maybe thats the problem)