简体   繁体   English

如何使用 PHPSESSID 读取会话

[英]How to read a session with a PHPSESSID

I Know A PHPSESSID in the server how can i read a session variable that is set to a PHPSESSID ( i don't want to use $_SESSION because i don't want start session in this thread ) i only want read session data with using PHPSESSID ??我知道服务器中的 PHPSESSID 如何读取设置为 PHPSESSID 的会话变量(我不想使用 $_SESSION,因为我不想在此线程中启动会话)我只想使用使用读取会话数据PHPSESSID ?? PHP : PHP :

<?php
namespace MyApp;
class readSession extends \Thread {
    private $sess_id,$data_name;
    public function __construct($SESSID,$data_name){
        $this->sess_id = $SESSID;
        $this->data_name = $data_name;
    }
    public function run(){
        $data = $this->readSession($this->sess_id,$this->data_name);   
    }
    private function readSession($SESSID,$data_name){
        session_id($SESSID);
        session_start();
        $temp = $_SESSION[$data_name];
        var_dump($_SESSION);
        session_destroy();
        return $temp;
    }    
}

i write this code to read users session's data but it remove the users session data我写这段代码来读取用户会话的数据,但它删除了用户会话数据

First of all, reading another user's session data is a horrible idea.首先,读取另一个用户的会话数据是一个可怕的想法。 If you need to have shared access to that data - don't store it in the session.如果您需要对该数据进行共享访问 - 不要将其存储在会话中。

Secondly, reading another doing it via session_start() with the same session ID is an even worse idea - that way you are effectively acting as that user.其次,通过session_start()使用相同的会话 ID 读取另一个执行操作是一个更糟糕的主意 - 这样您就可以有效地充当该用户。 There's no easy/reliable way to read session data without intercepting it, but that's not by accident, it's exactly because you shouldn't do it.没有简单/可靠的方法可以在不拦截的情况下读取会话数据,但这并非偶然,正是因为您不应该这样做。

That being said, don't call session_destroy() and the user's data won't be removed ... destroy means destroy.话虽如此,不要调用session_destroy()并且用户的数据不会被删除...... destroy 意味着销毁。 If you're looking for a way to just close a session, that's session_write_close() .如果您正在寻找一种关闭会话的方法,那就是session_write_close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM