Merge pull request #559 from fermionic/20121224-better-cookie-handling

delete cookie on browser close after logout
This commit is contained in:
fermionic 2012-12-25 11:07:51 -08:00
commit b4738906ac

View file

@ -5,6 +5,8 @@ require_once('include/security.php');
require_once('include/datetime.php'); require_once('include/datetime.php');
function nuke_session() { function nuke_session() {
new_cookie(0); // make sure cookie is deleted on browser close, as a security measure
unset($_SESSION['authenticated']); unset($_SESSION['authenticated']);
unset($_SESSION['uid']); unset($_SESSION['uid']);
unset($_SESSION['visitor_id']); unset($_SESSION['visitor_id']);
@ -187,18 +189,10 @@ else {
// (i.e. expire when the browser is closed), even when there's a time expiration // (i.e. expire when the browser is closed), even when there's a time expiration
// on the cookie // on the cookie
if($_POST['remember']) { if($_POST['remember']) {
$old_sid = session_id(); new_cookie(31449600); // one year
session_set_cookie_params('31449600'); // one year
session_regenerate_id(false);
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
} }
else { else {
$old_sid = session_id(); new_cookie(0); // 0 means delete on browser exit
session_set_cookie_params('0');
session_regenerate_id(false);
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
} }
// if we haven't failed up this point, log them in. // if we haven't failed up this point, log them in.
@ -208,4 +202,10 @@ else {
} }
} }
function new_cookie($time) {
$old_sid = session_id();
session_set_cookie_params("$time");
session_regenerate_id(false);
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
}