Emulate session from cached session id

@param mixed $session
@param string $sessionID
494161
private function setSession($session, $sessionID)
    {
        // close current session
        $session->writeClose();
        // set session id (to value loaded from cache)
        $session->setSessionId($sessionID);
        // re-start the session
        $session->start();
    }
365577
public static function setSession($client_id, array $session)
    {
        if (Context::$client_id === $client_id) {
            $_SESSION = $session;
            Context::$old_session = $_SESSION;
        }
        static::setSocketSession($client_id, Context::sessionEncode($session));
    }
21243
public function read($sessionId)
    {
        $sql = "SELECT {$this->options['data_col']} 
 FROM {$this->options['table']} 
 WHERE {$this->options['id_col']} = :id";

        try {
            $stmt = $this->db->prepare($sql);

            $stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);

            $stmt->execute();

            // We use fetchAll instead of fetchColumn to make sure the DB cursor gets closed
            $sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM);

            if ($sessionRows) {
                return base64_decode($sessionRows[0][0]);
            }

            return '';
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                sprintf(
                    'PDOException was thrown when trying to read the session data: %s',
                    $e->getMessage()
                ),
                0,
                $e
            );
        }
    }
377457
public function destroy($sessionId)
    {
        parent::destroy($sessionId);
        if (isset($_COOKIE[$this->cookieKeyName])) {
            setcookie($this->cookieKeyName, '', 1);
            unset($_COOKIE[$this->cookieKeyName]);
        }
        return true;
    }
1088858
public void createSession(String sessionId) {
        boolean newSession = sessionId == null;
        sessionId = newSession ? newSessionId() : sessionId;
        SessionController controller = sessions.get(sessionId);
        
        if (controller == null) {
            controller = SessionController.create(sessionId, newSession);
            sessions.put(sessionId, controller);
        }
    }
1285822
protected function setSessionId($sessionId, $validateSessionId = true)
    {

        if ($validateSessionId) {
            if (!$this->sessionIdIsValid($sessionId)) {
                $sessionId = false;
            }
        }

        if (!$sessionId) {
            $sessionId = $this->generateSessionId();
        }

        $this->session_id = $sessionId;

        // Not relying on session to retrieve it's ID from the cookie
        session_id($sessionId);

        // Will set cookie automatically anyway, let's try to control it
        session_set_cookie_params(
            self::$config['cookie']['lifetime'],
            self::$config['cookie']['path'],
            self::$config['cookie']['domain'],
            self::$config['cookie']['secureOnly'],
            self::$config['cookie']['httpOnly']
        );

        session_name(self::$config['cookie']['name']);
    }
478136
protected function doWrite($sessionId, $data)
    {
        $item = $this->getCacheItem($sessionId);
        $item->set($data)
            ->expiresAfter($this->ttl);

        return $this->cache->save($item);
    }
141695
public function setSessionId($sessionId)
    {
        $this->set(self::MAUTIC_SESSION_ID, $sessionId);
        $this->set(self::MTC_SID, $sessionId);

        return $this;
    }
239454
protected static function &register_store_id($id) {
        if (is_null(self::$sessionstore)) {
            global $SESSION;
            if (!isset($SESSION->cachestore_session)) {
                $SESSION->cachestore_session = array();
            }
            self::$sessionstore =& $SESSION->cachestore_session;
        }
        if (!array_key_exists($id, self::$sessionstore)) {
            self::$sessionstore[$id] = array();
        }
        return self::$sessionstore[$id];
    }
393110
public function session($session_id)
	{
		$query = $this->connection->getQuery()
			->select('*')
			->from('#__session')
			->group('userid')
			->group('client_id')
			->order('time', 'desc');

		$this->connection->setQuery($query->toString());
		return $this->connection->loadObject();
	}
693595
public function read($splash, $session, $sessionId)
    {

        $database = $this->database;
        //$token = (string) $input->getCookie($sessId);
        $statement =
            $database->where("session_agent", $database->quote($splash['agent']))
                ->where("session_ip", $database->quote($splash['ip']))
                ->where("session_host", $database->quote($splash['domain']))
                ->where("session_key", $database->quote($sessionId))
                ->select("*")->from($session->table)->prepare();

        $result = $statement->execute();

        //Do we have a session that fits this criteria in the db? if not destroy
        if ((int)$result->rowCount() < 1) {
            $session->destroy($sessionId);
            return false; //will lead to re-creation
        }

        $object = $result->fetchObject();

        return $object;
    }
637698
protected function doWrite($sessionId, $data): bool
    {
        $this->sessionDataProvider->setData($data);
        $this->getFacade()->setEx($this->prefix . $sessionId, $this->sessionDataProvider, 'ex', $this->ttl);

        return true;
    }
15891
private function loadFromFile(SessionInterface $session)
    {
        $id = preg_replace('/[^\w\-]+/', '-', $session->getId());
        $dir = (new Config())->getSessionDir();
        $filename = "$dir/sess-$id/sess-$id.json";
        if (is_readable($filename) && ($contents = file_get_contents($filename))) {
            $data = json_decode($contents, true) ?: [];
            $session->setData($data);
            $this->save($session);
            // Reload the session from the keychain, and delete the file if
            // successful.
            if (rename($filename, $filename . '.bak')) {
                $this->load($session);
                if ($session->getData()) {
                    unlink($filename . '.bak');
                }
            }
        }
    }
706114
protected function doDestroy($sessionId): bool
    {
        $this->getFacade()->delete($this->prefix . $sessionId);

        return true;
    }
811422
public function destroy($sessionId)
    {
        // delete the record associated with this id
        $sql = "DELETE FROM {$this->options['table']} WHERE {$this->options['id_col']} = :id";

        try {
            $stmt = $this->db->prepare($sql);

            $stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);

            $stmt->execute();
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                sprintf(
                    'PDOException was thrown when trying to delete a session: %s',
                    $e->getMessage()
                ),
                0,
                $e
            );
        }

        return true;
    }
1068163
private static function setSessionId($sessionId){
        $sessionId = trim($sessionId);

        // 非法字符处理
        if (!$sessionId || preg_match("/[^0-9a-z_\\-\\,]/i", $sessionId)) {
            return false;
        }

        $sessionId = substr($sessionId, 0, 40);
        session_id($sessionId);

        return $sessionId;
    }
1138515
public function deleteSessionAction($sessionId, Request $request)
    {
        /** @var $session \Symfony\Component\HttpFoundation\Session\Session */
        $session = $request->getSession();
        if (!$session->isStarted() || $session->getId() != $sessionId || !$this->hasStoredCsrfToken()) {
            $response = $this->authenticator->logout($request);
            $response->setStatusCode(404);

            return $response;
        }

        $this->checkCsrfToken($request);

        return new Values\DeletedUserSession($this->authenticator->logout($request));
    }