Page 2 of 2

Posted: Wed Jul 27, 2005 10:54 pm
by br5dy
i have a session variable "username" and "password" set but my session seems to die after browser closes.

any ideas?

Posted: Thu Jul 28, 2005 8:12 am
by theda
That's what sessions do. They die when browser is closed. That's what it is supposed to do. Now, if you venture OFF your website, but still have the original window open, you can go back to the website and the session should still be alive. It's called security. There's even a way to kill a session if they venture out of the website...

Sessions aren't like cookies: They love to die when things are over, unlike cookies, which die whenever their timer ends.

Posted: Thu Jul 28, 2005 11:32 am
by br5dy
That's what I thought, however, is it possible to reload the session with cookies?

Posted: Thu Jul 28, 2005 11:41 am
by josh
Yes, set your cookies when they login, and whenever new session variables are created, when checking session variables check if a cookie exists also.

Posted: Thu Jul 28, 2005 11:51 am
by br5dy
Should I save the username and password strings inside the cookie? or just the session id? If so, how can I load those back into the session to activate it?

Posted: Thu Jul 28, 2005 11:53 am
by josh
session's are going to get garbage collected so storing the session id is no good, you want to store the username and some how safely store a hash of the password.

Loading it back is self explanatory:

Code: Select all

if (!isset($_SESSION['value'])) {
  if (!isset($_COOKIE['value'])) {
    $_SESSION['value']=$_COOKIE['value'];
  }
}

Posted: Thu Jul 28, 2005 11:56 am
by br5dy
haha oh yeah. thanks. 8O