问题
I have 3 login forms in my page, clicking logout is destroying all the sessions and logging them all out. I know that session_destroy() destroys all the data associated with the current session but could i give it a parameter or is there any way to specify which session to destroy? I have tried using unset without the session_destroy but it won't logout the user
Code edited:
<?php
if(isset($_GET['auth'])){
if($_GET['auth']=='parent'){
session_name('parent');
session_start();
if(isset($_SESSION['parent']))
unset($_SESSION['parent']);
session_destroy();
}}
if(isset($_GET['auth'])){
if($_GET['auth']=='employee'){
session_name('employee');
session_start();
if(isset($_SESSION['employee']))
unset($_SESSION['employee']);
session_destroy();
}}
if(isset($_GET['auth'])){
if($_GET['auth']=='student'){
session_name('student');
session_start();
if(isset($_SESSION['student']))
unset($_SESSION['student']);
session_destroy();
}}
header("Location: login.php");
?>
I have added session_name to get different sessions, i am able to destroy the session but i can't have multiple sessions in the same page!
回答1:
Please use session_start(); once at the top of the page. After successful login, please check all the sessions that is set, for example in your case.
$_SESSION['parent'];
$_SESSION['employee'];
$_SESSION['student'];
session_name(''); will override the previous session's name, so you don't have to use session_name here. If you check there is a value for specific session or the session name is exist unset($_SESSION('your_session_key')); Hope it will work. Thanks
来源:https://stackoverflow.com/questions/15040353/session-destroy-with-multiple-sessions