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
The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid. If the expiration is set to zero the cookie will only last as long as the browser is open.
So change your code to this :
$expire = (60*60*24*30);
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)