Forum Moderators: coopster
1. Clear out the $_COOKIE[session_name()] variable
2. Delete the session file sess_#*$!#*$! that corresponds to the session id in the directory.
But none of these happened. Is session_destroy sufficient for destroying the session in this version? And how do you check to see if it is destroyed?
Thanks.
so if you are validating your session then it won't validate because there is no data in there
hijacking is multi tiered
good destruction
strict time limits
as much user identification as you can
good session validation
doesn't matter whether the file is still there, doesn't even matter whether the cookie is still there, if your validation is good they can't get anywhere
// session_name('mySession'); // if you have named your session
session_start();
$_SESSION = array();
session_destroy();
Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal.[php.net...]
I've done some extensive testing and found the approach shown above to be most favorable. And in regards to the session_unset() function, here is a past discussion that may be of some interest:
[webmasterworld.com...]
well you could look at this thread for some ideas
[webmasterworld.com...]
you obviously set values in the session, you also know what those values/variables are. For your authentication you can make sure they are present, you can also check some of the values.
It all depends on what is in there
session_destroy(S_SESSION['username']);
The session_destroy function takes nothing as an argument, therefore this won't really work. What you can do, however, is unset the session variable:
[url=http://us3.php.net/manual/en/function.unset.php]unset[/url]($_SESSION['var']);
session_destroy(S_SESSION['username']);The session_destroy function takes nothing as an argument, therefore this won't really work. What you can do, however, is unset the session variable:
unset($_SESSION['var']);
This is what I've been doing. Seems to work just fine, and you can always restart the session.
>> what constitutes good session validationwell you could look at this thread for some ideas
[webmasterworld.com...]you obviously set values in the session, you also know what those values/variables are. For your authentication you can make sure they are present, you can also check some of the values.
It all depends on what is in there
Checked out the link you provided. I'm doing all of these, about your suggestion on keeping user's IP in a session: this would not work with many of my users. I've tried this before and a lot of them have providers that change their IP addresses frequently, event within 1 request. For example, just looking at server log, I'd have resources a.gif with referrer URL of aa.html (my own page) from IP 200.aa.bb.cc then in the same second, resources b.gif from reffer aa.html with IP 200.aa.bb.dd. So a lot of my users complained they were logged out in the middle of a session. The only thing reliable to stay constant is may be the first 3 blocks or 2 blocks of the IP address (200.aa.bb), not the whole IP address.
So I guess we could use that and some other unique stuff about the user like his browser string, ect...
$path = "/path/to/sessions/folder/";$files = array();
foreach ($_SESSION as $key => $value) {
$files[] = $key;
unset($_SESSION[$key]);
}foreach ($files as $file) {
unlink($path . "sess_" . $file);
}
Haven't tested it but assuming you can access the session folder it should work. Also make use of session_regenerate_id() for session hijack prevention.
[edited by: FiRe at 3:56 pm (utc) on Feb. 23, 2007]
Session security works on the basis that the session ID is hard to guess. Not having to guess it makes thinsg easier.PHP can accept session IDs through a cookie or URL.
Stealing sessions allows you to take over a logged-in user.
Session fixation means having a user follow a link with a provided session id in the URL. If they then login, you could connect with the session ID you provided and use their credentials.
Use session_regenerate_id() whenever a user logs in or changes their privilege level so an attacker cannot go back in and use the session id the provided to the target.