douyuefei3546 2011-09-05 05:07
浏览 52
已采纳

跳转到另一个现有会话(使用PHP的默认会话处理程序)

I have a scenario like this:

UserJoe has session_id abc123 abc123 is stored in UserJoe's row in the users table in the DB.

UserJoe calls AdminBob and reports a problem.

AdminBob needs to experience UserJoe's problem first hand

So, I'd like to do something like:

01|  $sessionId = getSessionId("UserJoe");
02|  changeToExistingSession($sessionId);
03|  if($_SESSION["name"] == "UserJoe") echo "successfully changed users";

Line 02 is where I'm kinda stuck... Any ideas?

(preferably not using session_save_path() anywhere :P)

EDIT: And it's just for the duration of the page execution. I'd like to keep AdminBob's session cookie intact.

  • 写回答

1条回答 默认 最新

  • dongwen1871 2011-09-05 05:18
    关注

    If you store UserJoe's session ID in a database together with the report, then I think you can use session_id() to set AdminBob's session ID to UserJoe's session id.

    <?php
      if(!isset($_GET["id"]))
      {
        session_start();
        $_SESSION["foobar"] = $_GET["bar"];
        echo "Setting...";
        var_dump($_SESSION);
        var_dump($_COOKIE);
      }
      else
      {
        session_id($_GET["id"]);
        var_dump($_GET["id"]);
        var_dump($_COOKIE);
        session_start();
        var_dump($_SESSION);
      }
    ?>
    

    To test: Open this page in one browser and set bar to anything.

    index.php?bar=blahblahblah
    

    Open a new browser and visit the same page but do not set bar, get the value of PHPSESSID and set it as id's value

    index.php?id=[value of PHPSESSID]
    

    You should see the other browser's session in the newly opened browser

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向