Page 1 of 1
$_SESSION[] problems
Posted: Fri Oct 31, 2008 12:39 am
by ThuggLife
Hi, I'm writing a login script that uses a session variable to remember authenticated users. The problem is that I want the session to die when the browser is closed, but it doesn't. It used to erase the session when the browser was closed but then for no apparent reason it stopped working. I was under the impression that the default for session variables is to erase when the browser is closed but mine arn't erased. Is there any way to kill the session variable when the browser is closed?
Re: $_SESSION[] problems
Posted: Fri Oct 31, 2008 1:02 am
by novice4eva
SESSIONS are cleared after certain time passes, this configuration is saved in apache configuration(i think), there is a PHP function to set this time limit namely "session_cache_expire". As for the catching the event in window close, i don;t think there is any such javascript that does it, apparently they didn't put this function because they thought someone would do like this
if (close my window event)
{
don't close the window

;
}
humm makes sense why they didn't make catching window close event, doesn't it?
Re: $_SESSION[] problems
Posted: Fri Oct 31, 2008 5:22 am
by jarnail
You can try cookies. At the time of creating cookies don't set its time. The cookie will be deleted with the close of browser.
ie
cookie can be set in this way:
setcookie("cookiename",$value, time()+3600*24);
but for you requirement use only:
setcookie("cookiename",$value);
Re: $_SESSION[] problems
Posted: Fri Oct 31, 2008 3:14 pm
by califdon
Session variables are kept on the server, so the server has no way to know that a viewer has closed their browser or browsed to a different page or even died at the keyboard.
Re: $_SESSION[] problems
Posted: Fri Oct 31, 2008 4:02 pm
by mmj
novice4eva wrote:As for the catching the event in window close, i don;t think there is any such javascript that does it, apparently they didn't put this function because they thought someone would do like this
if (close my window event)
{
don't close the window

;
}
humm makes sense why they didn't make catching window close event, doesn't it?
https://developer.mozilla.org/En/DOM/Wi ... foreunload
Re: $_SESSION[] problems
Posted: Sun Nov 02, 2008 6:00 am
by novice4eva
weeeeeeee

mmj thanks for that link