I'm learning on how to do session management on PHP and trying to allow only one login session by using session_id()
to generate login session hash, but it seems that something is wrong, because each time i call out session_id()
i will be returned the same hash 0b055b4f53310060d84535ee8e3bf663
. I tried logging in with multiple users, it's returning same hash for each login session and for each user.
//Login.php:
session_start(); // Starting Session
//Take inputs, do user query
if (queryResultRows == 1){
$_SESSION['userid']=$userinfo["uid"];
$_SESSION['userlevel']=$userinfo["userlevel"];
$_SESSION['login_user']=$username; // Initializing Session
$sessionid = session_id();
//Insert sessionId into DB..
//Redirect to next page.
}
//Logout.php:
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: index.php"); // Redirecting To Home Page
}
Now i tried to do login, i successfully had access to all session restricted areas on my page (session was created and is working) then initated logout.php, the session was destroyed, i had no longer access, did login again, but the session_id()
value was still the same. Any ideas what i'm doing wrong here?