具有多个会话的session_destroy() [英] session_destroy() with multiple sessions
问题描述
我的页面上有3个登录表单,单击注销将销毁所有会话并将其全部注销.我知道session_destroy()会销毁与当前会话相关的所有数据,但是我可以给它一个参数还是有什么办法指定要销毁的会话?我已经尝试过在没有session_destroy的情况下使用unset,但是它不会注销用户
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
代码已
<?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");
?>
我添加了session_name来获得不同的会话,我可以销毁该会话,但是在同一页面中不能有多个会话!
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!
推荐答案
请使用session_start();在页面顶部一次.成功登录后,请检查所有已设置的会话,例如您的情况.
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('');将覆盖上一个会话的名称,因此您不必在此处使用session_name.如果您检查特定会话的值或会话名称是否存在未设置($ _SESSION('your_session_key'));希望它能工作.谢谢
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
这篇关于具有多个会话的session_destroy()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!