I'm just implementing a login and logout system using PHP and experiencing problems with logout. The system outline is as follows:
When the user logs in, a session is created with a session variable "user" and "stud" as i'm creating it for student and admin.
After the session is set up, the user is redirected to home.php file.
In that file, a logout button is placed. When the user clicks the logout button session destroyed, but it destroyed both account. I try login both account, student and admin, but when i try logout for admin, it'll destroyed both account.
Anyone can help me with this problem?
here is my coding for admin logout:
session_start(); if(!isset($_SESSION['user'])) { header("Location: index.php"); } else if(isset($_SESSION['user'])!="") { header("Location: homeAdmin.php"); }
if(isset($_GET['adminLogout'])) { session_destroy(); unset($_SESSION['user']); header("Location: index.php"); }
You have maintain the sessions for user and admin separately like
$_SESSION['user'] and $_SESSION['stud']
and destroy the respective session on logout process. Means if logout the user than destroy only$_SESSION['user']