ramesh
ramesh

Reputation: 4082

Cookie expires on session out in Codeigniter

I am setting a cookie in my codeigniter application using the following code. Working fine .. but cookie get expires on session out.. Please help

$cookie = array(
        'name'   => 'tvcUsername',
        'value'  => $email,
        'expire' => time()+86500,
        'domain' => 'http://localhost/tvc',
        'path'   => '/',
        'prefix' => '',

    );

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

Thanks in advance

Upvotes: 1

Views: 3268

Answers (2)

Eyad Farra
Eyad Farra

Reputation: 4423

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.

source: http://ellislab.com/codeigniter/user-guide/libraries/input.html

Upvotes: 0

Robbie
Robbie

Reputation: 17710

Two things I can think of:

a) localhost is not a valid domain, so cookies won't be saved for all browsers. Create yourself a HOST for "my.dev.server" or "localhost.dev" and point to 127.0.0.1 (you may also need to configure apache to respond to that name - but try it first just changing the HOSTS file first)

b) In addition, your "domain" includes a scheme and a path - that might be causing problems? Set to "localhost.dev" (drop the "http://" and the "/tvc" parts - once you've moved away from localhost.

Upvotes: 1

Related Questions