Is there a reason to fill session property with values from database?
1
$_SESSION['hash'] = query_row['hash']; //hash from database; unique to each user
and then on each page, check if session exist
if(isset($_SESSION['hash'])) && $db->checkLogin()
{
//user session is still valid
}
whereby:
function checkLogin($session_hash)
{
if($_SESSION['hash'])
{
//check if $session_hash is found in database
}
}
instead of using
2
$_SESSION['islogged_in'] = true;
and only check if session is set
if(isset($_SESSION['islogged_in']))
{
//user session is still valid
}
Does using the first method give you any more protection? Is it wise to set the session value with something unique instead of 'true'? Is it wise to validate the $_SESSION[] value with databank data? And WHY would it be safer?
EDIT: I know which are the standard methods to protect sessions against fixation and Hijacking. This is not my question :)
I can't find a reason to use method 1 at all (so validating with databank or even setting session property with unique data like username, ..) As far as I know, session properties are being saved server side, so users/hackers can't modify them. Session protection (hijacking and fixation) only protects the session id since this is the only thing that's being save on client in cookie (so can be modified). I see lots of programmers on the internet do this anyway, so that's why I'm asking.