Cookie gets deleted on restarting browser

The cookie which i set in codeigniter gets deleted after i restart the browser. I'm setting up a cookie like:

$test_cookie = array(
                    'name'=>'test',
                    'value'=> 'test',
                    'expire'=> time() + 60*60*24*14
                );

$this->input->set_cookie($test_cookie);  

The print_r($test_cookie) returns:

Array ( [name] => test [value] => test [expire] => 1309943188 ) 

Now i can print the cookie to make sure that the cookie is set:

$test_cookie= $this->input->cookie('test');
echo "<b> Cookie value: </b>". $test_cookie;

The cookie prints the value correctly.

However, if i restart the browser, i don't get the cookie value anymore. I've tried multiple browsers. With the var_dump, i get: bool(false) Why the cookie is getting deleted when browser restarts?

Thanks.

Answers


The CodeIgniter documentation says the expires value is added to the current time. So effectively the expires value in your case is time() + time() + 60*60*24*14. This may be beyond the 32 Bit integer limit and turn into a negative value. This in turn will result in a temporary cookie that's deleted upon closing the browser.

$test_cookie = array(
  'name'=>'test',
  'value'=> 'test',
  'expire'=> 60*60*24*14
);

should work. I think.


Need Your Help

NHibernate.Driver.FirebirdClientDriver does not support multiple queries

c# nhibernate

I'm using nhibernate as orm in my app and firebird as database.

Check that a given date does not lie between two existing dates inside a datatable

c# asp.net sql database linq

I have one table which can store student leave start date and end date

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.