views:

283

answers:

5

Let's suppose I have a sign-in form. When I sign in successfully I am redirected to the logged in home page. Currently, when I close this page without signing out, and re-open Firefox, this logged in home page is started again.

I want it so that when the user closes their browser the session is the session is expired and when they next open Firefox the logged-in home page isn't displayed.

I think session will be used for this, but I don't know how I can set a time or even make it so that when Firefox closes the closes session get destroyed.

A: 

You may want to read this:

http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes

Felix Kling
I really would like to know why this answer is not useful. It answers the question *how i can set time*.
Felix Kling
+1  A: 

Set your session timeout to 15 minutes, this should do the job. You cannot catch the "close browser" or "close tab" event for sure (no javascript enabled, browser just crashes, etc), so you shouldn't go for that.

Check Felix' post for additional information where to set the session timeout exactly.

Karsten
Downvote without comment?
Karsten
Happened to me on another thread this morning too. Apparently on Sunday we're supposed to "just know".
AJ
I'm guessing that it was because of the 15min recommendation.
Blair McMillan
+2  A: 

You want the session cookie to have an expire time of 0 - see:

http://php.net/manual/en/function.setcookie.php

http://docs.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime

therefromhere
A: 

Pardon me if I am stepping on toes as non-server HTML programmer, but could you check to see if the browser already has a cookie from a previous session? Even if the answer is yes, if it is a new session, force an authentication?

Just a thought.

Neil
A: 

$_SESSION would help you in that.... for more information go to php.net

Ahsan