【问题标题】:How to destroy only one session and other session are working as on如何只销毁一个会话和其他会话正在工作
【发布时间】:2015-09-09 03:59:36
【问题描述】:
<?php
include('session_sty_chk.php');
session_start();
if(session_destroy()) // Destroying All Sessions
{

//echo "<script>alert('$login_sessionn log out successfully');</script>";
echo"<script>window.location.href = 'index_sty_chk.php';</script>";
//header("Location: index.php"); // Redirecting To Home Page
}
?>

以上代码是会话销毁代码。

在我的应用程序中,我创建了两个会话 会议名称:- 1:-管理员, 2:-社会用户

当我点击注销按钮时,然后破坏管理员和社会用户会话。

所以先生,我只想破坏应用程序中的社会用户会话,所以请帮我解决它。

【问题讨论】:

标签: php


【解决方案1】:
unset($_SESSION['society user']);

使用此代码

【讨论】:

  • 我在使用上面的功能,但是它不起作用....如何在会话代码中使用上面的功能.????????
  • 这里的示例代码:”;未设置($_SESSION['society_user']); echo "会话未设置:" .@$_SESSION['society_user']; ?>
  • @KirankumarGajananGawade 你检查过我的cmets吗
  • 先生,请给出我包含但它不起作用的代码。
【解决方案2】:

来自php网站:

<?php
$session_id_to_destroy = 'nill2if998vhplq9f3pj08vjb1';
// 1. commit session if it's started.
if (session_id()) {
    session_commit();
}

// 2. store current session id
session_start();
$current_session_id = session_id();
session_commit();

// 3. hijack then destroy session specified.
session_id($session_id_to_destroy);
session_start();
session_destroy();
session_commit();

// 4. restore current session id. If don't restore it, your current session will refer to the session you just destroyed!
session_id($current_session_id);
session_start();
session_commit();

?>

链接:http://php.net/manual/en/function.session-destroy.php#114709

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-08
    • 1970-01-01
    • 2018-12-24
    • 2012-09-23
    • 2016-09-17
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多