I’ve a admin panel and user panel. Both have a Logout link. When I login to admin panel and in the mean time i login as a user. So both have a session.
But when i logout from admin panel it’s also logged from user panel. Why it’s logout from user. I did seperate login session.
Login Session for Admin and User:
$_SESSION['admin_u'] = $admin_uname;
$_SESSION['admin_pass'] = $admin_pass2;
and
$_SESSION['uname'] = $uname;
$_SESSION['pass'] = $pass;
Admin Logout code:
<?php
if(isset($_SESSION['admin_u']) && isset($_SESSION['admin_pass'])) {
session_unset($_SESSION['admin_u']);
session_unset($_SESSION['admin_pass']);
session_destroy();
header( "Location:../index.php" );
exit();
} else {
header("Location:../membersignin.php");
exit();
}
?>
User Logout code:
<?php
if(isset($_SESSION['uname']) && isset($_SESSION['pass'])) {
session_unset($_SESSION['uname']);
session_unset($_SESSION['pass']);
session_destroy();
header( "Location:../../index.php" );
exit();
} else {
header("Location:../../membersignin.php");
}
?>
Is there anything wrong in my code?
session_destroy()This being called implies the session, both user, and admin is being destroyed. You should simply unset the session variables you don’t want and not destroy the session, if you don’t want to be logged out of both.
Also, you are using
session_unset()incorrectly. The session_unset() function frees all session variables currently registered. Use a plainunset()instead.