$_SESSION[] problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ThuggLife
Forum Newbie
Posts: 13
Joined: Wed Oct 08, 2008 9:10 pm

$_SESSION[] problems

Post 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?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: $_SESSION[] problems

Post 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 :twisted: ;
}

humm makes sense why they didn't make catching window close event, doesn't it?
jarnail
Forum Newbie
Posts: 7
Joined: Thu Oct 30, 2008 8:44 am

Re: $_SESSION[] problems

Post 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);
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: $_SESSION[] problems

Post 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.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: $_SESSION[] problems

Post 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 :twisted: ;
}

humm makes sense why they didn't make catching window close event, doesn't it?
https://developer.mozilla.org/En/DOM/Wi ... foreunload
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: $_SESSION[] problems

Post by novice4eva »

weeeeeeee :drunk: mmj thanks for that link
Post Reply