notnotundefined
notnotundefined

Reputation: 3751

PHP Session Cookie

I have a php session . It's lifetime expiration is set to 1 week from current date(30-dec-2013).

Scenario: 1. Changed system time to 6th January 2014 , then expiry date changed to 13th Jan 2014 (i.e one week from 6th Jan 2014). 2. Now again I changed system time to current date and time (30-dec-2013),

Doubt: Still the expiry date is shown as 13th Jan 2014 , Should not it be 6th Jan, since it is set for one week from today's date?

Thanks in advance!!

Upvotes: 0

Views: 288

Answers (1)

Noishe
Noishe

Reputation: 1421

When you increased the time of your machine, the cookie was expired and so was not sent. As such, the server generated a new cookie with a new expiry date.

When you decreased the time on your machine, the cookie was still valid, so it was sent. PHP saw the valid cookie and so saw no reason to issue a new cookie with a new expiry date.

If you want to force php to emit a new cookie with a new expiry date, even if the old cookie is still valid, then put this snippet in your code before calling session_start.

if(isset($_COOKIE[session_name()]))
{
    session_id(session_id());
}

Upvotes: 1

Related Questions