0

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!!

2
  • Did you reset the session after you set the date back to today? Commented Dec 30, 2013 at 13:02
  • Try that in the Private Mode of your browser (Crtl+shift+P in Firefox). There you are shure that you don't have already an Session open Commented Dec 30, 2013 at 13:06

1 Answer 1

1

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());
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.