Reads the session data.

@see http://php.net/sessionhandlerinterface.read

@param string $sessionId Session ID, see http://php.net/function.session-id

@return string Same session data as passed in write() or empty string when non-existent or on failure
6798
public function read($sessionId)
    {
        $this->sessionExpired = false;

        $selectSql = $this->getSelectSql();
        $selectStmt = $this->db->query($selectSql)
                        ->bind(':id', $sessionId);

        $sessionRows = $selectStmt->row();

        if ($sessionRows) {
            if ($sessionRows->{$this->timeCol} + $sessionRows->{$this->lifetimeCol} < time()) {
                $this->sessionExpired = true;

                return '';
            }

            return is_resource($sessionRows->{$this->dataCol}) ? stream_get_contents($sessionRows->{$this->dataCol}) : $sessionRows->{$this->dataCol};
        }

        return '';
    }
345008
public function getUserIdFromSessionId($sessionId)
	{
		$database = \App::get('db');

		// get session timeout period
		$timeout = \App::get('config')->get('timeout');

		// load user from session table
		$sql = "SELECT userid 
				  FROM `#__session`
				  WHERE `session_id`=" . $database->quote($sessionId) . "
				  AND time + " . (int) $timeout . " <= NOW();";
				//  AND client_id = 0;";
		$database->setQuery($sql);
		return $database->loadResult();
	}
712806
public function session_read($session_id)
    {
        // Set empty result
        $this->session_data = (string)'';

        // Fetch session data from the selected database with the correct
        // timestamp
        $time       = (int)time();
        $session_id = mysql_real_escape_string($session_id);
        $sql        = (string)"SELECT `session_data` FROM `{$this->_db_name}`.`user_session` WHERE `session_id` = '$session_id' AND `expires` > $time";

        $session_res = $this->db->query((string)$sql);
        // if no session data exists return false
        if (empty($session_res)) return false;
        $this->session_data = $this->db->fetch_string($session_res);
        $this->db->free($session_res);

        // session data is set uncompressed
        return $this->session_data;
    }
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
            );
        }
    }
387386
public function read($sessionid)
    {
        $sess = $this->getDbData($sessionid);

        if ($sess === null) {
            return '';
        } else {
            if ($this->getAdapter() instanceof PostgreSQL) {
                return hex2bin(is_resource($sess->data) ? stream_get_contents($sess->data) : $sess->data);
            } else {
                return $sess->data;
            }
        }
    }
49570
public function read($session_id)
	{
		// Get the database connection object and verify its connected.
		if (!$this->connection->connected())
		{
			return false;
		}

		try
		{
			// Get the session data from the database table.
			$query = $this->connection->getQuery()
				->select('data')
				->from('#__session')
				->whereEquals('session_id', $session_id);

			$this->connection->setQuery($query->toString());

			return (string) $this->connection->loadResult();
		}
		catch (Exception $e)
		{
			return false;
		}
	}
359879
public function write($sessionID, $sessionData): bool
    {
        $result = false;
        $file = $this->savePath.DIRECTORY_SEPARATOR.'sess_'.$sessionID;
        $handle = @\fopen($file, 'wb');
        if ($handle) {
            @\flock($handle, LOCK_EX);
            $result = @\fwrite($handle, $sessionData) !== false ? true : false;
            @\flock($handle, LOCK_UN);
            @\fclose($handle);
        }
        @\chmod($file, 0600);
        return $result;
    }
1074804
public static function read($id)
    {
        return (string)Symphony::Database()->fetchVar(
            'session_data',
            0,
            sprintf(
                "SELECT `session_data`
                FROM `tbl_sessions`
                WHERE `session` = '%s'
                LIMIT 1",
                Symphony::Database()->cleanValue($id)
            )
        );
    }
1141343
public function retrieve($sessionId)
    {
        try {

            $stream = $this->getRetrievalStream($sessionId);
            $stream->open();
            $access = $this->createBinaryStreamAccess($stream);

            // -- Deal with intrinsic values of the Test Session.
            $assessmentTestSessionState = $access->readTinyInt();
            $currentPosition = $access->readTinyInt();

            if ($access->readBoolean() === true) {
                $timeReference = $access->readDateTime();
            } else {
                $timeReference = null;
            }
            
            $visitedTestPartIdentifiers = array();
            $visitedTestPartIdentifiersCount = $access->readTinyInt();
            for ($i = 0; $i < $visitedTestPartIdentifiersCount; $i++) {
                $visitedTestPartIdentifiers[] = $access->readString();
            }
            
            $path = $access->readPath();
            
            // -- Session configuration.
            $config = $access->readShort();

            // Build the route and the item sessions.
            $route = new Route();
            $lastOccurenceUpdate = new SplObjectStorage();
            $itemSessionStore = new AssessmentItemSessionStore();
            $pendingResponseStore = new PendingResponseStore();
            $routeCount = $access->readTinyInt();

            // Create the item session factory that will be used to instantiate
            // new item sessions.
            
            $seeker = $this->getSeeker();

            for ($i = 0; $i < $routeCount; $i++) {
                $routeItem = $access->readRouteItem($seeker);
                $route->addRouteItemObject($routeItem);
                
                // An already instantiated session for this route item?
                if ($access->readBoolean() === true) {
                    $itemSession = $access->readAssessmentItemSession($this->getManager(), $seeker);
                    
                    // last-update
                    if ($access->readBoolean() === true) {
                        $lastOccurenceUpdate[$routeItem->getAssessmentItemRef()] = $routeItem->getOccurence();
                    }
                    
                    // pending-responses
                    if ($access->readBoolean() === true) {
                        $pendingResponseStore->addPendingResponses($access->readPendingResponses($seeker));
                    }

                    $itemSessionStore->addAssessmentItemSession($itemSession, $routeItem->getOccurence());
                }
            }

            $route->setPosition($currentPosition);
            $manager = $this->getManager();
            $assessmentTestSession = $manager->createAssessmentTestSession($this->getAssessmentTest(), $route, $config);
            $assessmentTestSession->setAssessmentItemSessionStore($itemSessionStore);
            $assessmentTestSession->setSessionId($sessionId);
            $assessmentTestSession->setState($assessmentTestSessionState);
            $assessmentTestSession->setLastOccurenceUpdate($lastOccurenceUpdate);
            $assessmentTestSession->setPendingResponseStore($pendingResponseStore);
            $assessmentTestSession->setTimeReference($timeReference);
            $assessmentTestSession->setVisitedTestPartIdentifiers($visitedTestPartIdentifiers);
            $assessmentTestSession->setPath($path);

            // Build the test-level global scope, composed of Outcome Variables.
            foreach ($this->getAssessmentTest()->getOutcomeDeclarations() as $outcomeDeclaration) {
                $outcomeVariable = OutcomeVariable::createFromDataModel($outcomeDeclaration);
                $access->readVariableValue($outcomeVariable);
                $assessmentTestSession->setVariable($outcomeVariable);
            }

            // Build the duration store.
            $durationStore = new DurationStore();
            $durationCount = $access->readShort();
            for ($i = 0; $i < $durationCount; $i++) {
                $varName = $access->readString();
                $durationVariable = new OutcomeVariable($varName, Cardinality::SINGLE, BaseType::DURATION);
                $access->readVariableValue($durationVariable);
                $durationStore->setVariable($durationVariable);
            }

            $assessmentTestSession->setDurationStore($durationStore);

            $stream->close();

            return $assessmentTestSession;
        } catch (Exception $e) {
            $msg = "An error occured while retrieving AssessmentTestSession. " . $e->getMessage();
            throw new StorageException($msg, StorageException::RETRIEVAL, $e);
        }
    }
1055784
public function touch(string $sessionId)
    {
        $file = "{$this->savePath}/{$this->sessionName}_{$sessionId}";
        if (file_exists($file)) {
            return touch($file, time());
        } else {
            return $this->getObject(\PG\MSF\Coroutine\File::class)->goWriteFile(
                "{$this->savePath}/{$this->sessionName}_{$sessionId}",
                '{}'
            );
        }
    }
319163
function read($session_id) {

        // get the lock name, associated with the current session
        // notice the use of sha1() which shortens the session ID to 40 characters so that it does not exceed the limit of
        // 64 characters for locking string imposed by mySQL >=5.7.5
        // thanks to Andreas Heissenberger (see https://github.com/stefangabos/Zebra_Session/issues/16)
        $this->session_lock = $this->_mysql_real_escape_string('session_' . sha1($session_id));

        // try to obtain a lock with the given name and timeout
        $result = $this->_mysql_query('SELECT GET_LOCK("' . $this->session_lock . '", ' . $this->_mysql_real_escape_string($this->lock_timeout) . ')');

        // stop if there was an error
        if (!$result || mysqli_num_rows($result) != 1 || !($row = mysqli_fetch_array($result)) || $row[0] != 1) throw new Exception('Zebra_Session: Could not obtain session lock!');

        //  reads session data associated with a session id, but only if
        //  -   the session ID exists;
        //  -   the session has not expired;
        //  -   if lock_to_user_agent is TRUE and the HTTP_USER_AGENT is the same as the one who had previously been associated with this particular session;
        //  -   if lock_to_ip is TRUE and the host is the same as the one who had previously been associated with this particular session;
        $hash = '';

        // if we need to identify sessions by also checking the user agent
        if ($this->lock_to_user_agent && isset($_SERVER['HTTP_USER_AGENT']))

            $hash .= $_SERVER['HTTP_USER_AGENT'];

        // if we need to identify sessions by also checking the host
        if ($this->lock_to_ip && isset($_SERVER['REMOTE_ADDR']))

            $hash .= $_SERVER['REMOTE_ADDR'];

        // append this to the end
        $hash .= $this->security_code;

        $result = $this->_mysql_query('

            SELECT
                session_data
            FROM
                ' . $this->table_name . '
            WHERE
                session_id = "' . $this->_mysql_real_escape_string($session_id) . '" AND
                session_expire > "' . time() . '" AND
                hash = "' . $this->_mysql_real_escape_string(md5($hash)) . '"
            LIMIT 1

        ');

        // if anything was found
        if ($result && mysqli_num_rows($result) > 0) {

            // return found data
            $fields = mysqli_fetch_assoc($result);

            // don't bother with the unserialization - PHP handles this automatically
            return $fields['session_data'];

        }

        // on error return an empty string - this HAS to be an empty string
        return '';

    }
447941
public function read($sessID)
    {
        $hander = is_array($this->hander) ? $this->hander[1] : $this->hander;
        $res = mysqli_query($hander, "SELECT session_data AS data FROM " . $this->sessionTable . " WHERE session_id = '$sessID'   AND session_expire >" . time());
        if ($res) {
            $row = mysqli_fetch_assoc($res);
            return $row['data'];
        }
        return "";
    }
820856
public function read($session_id)
    {
        $result = '';

        if ($this->getTable()->isConnected())
        {
            $row = $this->_table->select($session_id, KDatabase::FETCH_ROW);

            if (!$row->isNew()) {
                $result = $row->data;
            }
        }

        /*
         * It turns out that session_start() doesn't like the read method of a custom session handler
         * returning false or null if there's no session in existence.
         *
         * See: https://stackoverflow.com/a/48245947
         * See: http://php.net/manual/en/function.session-start.php#120589
         */
        return $result !== null ? $result : '';

    }
330571
protected function setSessionId($sessionId) {
    $session = ObjectFactory::getInstance('session');
    $sids = $session->get(self::SIDS_SESSION_VARNAME);
    $sids[$this->serverCli] = $sessionId;
    $session->set(self::SIDS_SESSION_VARNAME, $sids);
  }
374196
public function write(string $sessionId, string $sessionData)
    {
        return $this->getObject(\PG\MSF\Coroutine\File::class)->goWriteFile(
            "{$this->savePath}/{$this->sessionName}_{$sessionId}",
            $sessionData
        );
    }
135783
public function write($sessionId, $sessionData)
    {
        if ($this->_lock === false) {
            return $this->_fail();
        }

        $insertData = array(
            'id' => $sessionId,
            'ip_address' => $_SERVER['REMOTE_ADDR'],
            'timestamp' => time(),
            'data' => $sessionData
        );

        if (!$this->row_exists) {
            if ($this->newQuery()->insert($insertData)) {
                $this->_session_id = $sessionId;
                $this->row_exists = true;
                $this->_fingerprint = md5($sessionData);
                return $this->_success;
            }
        } else {
            if ($this->newQuery()->where('id', $this->_session_id)->update($insertData)) {
                $this->_session_id = $sessionId;
                $this->row_exists = true;
                $this->_fingerprint = md5($sessionData);
                return $this->_success;
            }
        }
        return $this->_fail();
    }
31847
public function read($id)
    {
        $session = $this->getPersistence()->get(self::KEY_NAMESPACE.$id); 
        return is_string($session) ? $session : '';
    }