How to create a cookie which never expire using Codeigniter

Maximum value of cookie expiration time is 2147483647 (2^31 – 1 = 2147483647 = 2038-01-19 04:14:07) [see: RFC 2616, 14.6 Age]

So the example code snippet:

// substracting current time from last exp. time because CI adds current time to the value
$unexpired_cookie_exp_time = 2147483647 - time();

$cookie = array(
	'name' => 'cookie_name',
	'value' => 'cookie_value',
	'expire'=> $unexpired_cookie_exp_time
);

$CI->input->set_cookie($cookie);

 

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *