PHP session

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

br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

i have a session variable "username" and "password" set but my session seems to die after browser closes.

any ideas?
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post 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.
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

That's what I thought, however, is it possible to reload the session with cookies?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post 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?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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'];
  }
}
br5dy
Forum Newbie
Posts: 22
Joined: Sat Jul 23, 2005 2:52 pm

Post by br5dy »

haha oh yeah. thanks. 8O
Post Reply