Read session handler.

{@see http://php.net/manual/en/function.session-set-save-handler.php}

@param string $sid
@return string
161409
public function handler_read($sid) {
        try {
            if (!$record = $this->database->get_record('sessions', array('sid'=>$sid), 'id')) {
                // Let's cheat and skip locking if this is the first access,
                // do not create the record here, let the manager do it after session init.
                $this->failed = false;
                $this->recordid = null;
                $this->lasthash = sha1('');
                return '';
            }
            if ($this->recordid and $this->recordid != $record->id) {
                error_log('Second session read with different record id detected, cannot read session');
                $this->failed = true;
                $this->recordid = null;
                return '';
            }
            if (!$this->recordid) {
                // Lock session if exists and not already locked.
                $this->database->get_session_lock($record->id, $this->acquiretimeout);
                $this->recordid = $record->id;
            }
        } catch (\dml_sessionwait_exception $ex) {
            // This is a fatal error, better inform users.
            // It should not happen very often - all pages that need long time to execute
            // should close session immediately after access control checks.
            error_log('Cannot obtain session lock for sid: '.$sid);
            $this->failed = true;
            throw $ex;

        } catch (\Exception $ex) {
            // Do not rethrow exceptions here, this should not happen.
            error_log('Unknown exception when starting database session : '.$sid.' - '.$ex->getMessage());
            $this->failed = true;
            $this->recordid = null;
            return '';
        }

        // Finally read the full session data because we know we have the lock now.
        if (!$record = $this->database->get_record('sessions', array('id'=>$record->id), 'id, sessdata')) {
            // Ignore - something else just deleted the session record.
            $this->failed = true;
            $this->recordid = null;
            return '';
        }
        $this->failed = false;

        if (is_null($record->sessdata)) {
            $data = '';
            $this->lasthash = sha1('');
        } else {
            $data = base64_decode($record->sessdata);
            $this->lasthash = sha1($record->sessdata);
        }

        return $data;
    }
929169
public function do_read($session_id)
    {
        $data = $this->_di->cookies->get($session_id) ?: '';
        if ($data === '') {
            return '';
        }

        $parts = explode('.', $data, 2);

        if (count($parts) !== 2) {
            throw new CookieException(['format invalid: `:cookie`', 'cookie' => $data]);
        }

        $key = $this->_key ?: $this->_getKey();
        if (md5($parts[0] . $key) !== $parts[1]) {
            throw new CookieException(['hash invalid: `:cookie`', 'cookie' => $data]);
        }

        $payload = json_decode(base64_decode($parts[0]), true);
        if (!is_array($payload)) {
            throw new CookieException(['payload invalid: `:cookie`', 'cookie' => $data]);
        }

        if (time() > $payload['exp']) {
            return '';
        }

        return $payload['data'];
    }
591740
public function getContext($sid) {
        return new InteractionContext(
            $this->version,
            $this->solution['serviceSid'],
            $this->solution['sessionSid'],
            $sid
        );
    }
1328865
public function read(string $sessionId)
    {
        $file = "{$this->savePath}/{$this->sessionName}_{$sessionId}";
        if (!is_file($file)) {
            return false;
        }

        return $this->getObject(\PG\MSF\Coroutine\File::class)->goReadFile($file);
    }
506952
protected function doUpdate($sid, $data, $uid=null) {
		$retval = null;
		$updateFields = array(
			'session_data'	=> $data,
			'session_id'	=> $sid,
		);
		
		if(!is_null($uid) && strlen($uid)) {
			$updateFields['uid'] = $uid;
		}
		elseif(!is_null($uid) && !strlen($uid)) {
			// no data in UID; it was specifically supplied empty, make it null in DB
			$updateFields['uid'] = null;
		}
		
		if(is_null($data)) {
			// Avoids accidentally removing session data.
			unset($updateFields['session_data']);
		}
		
		$sql = 'UPDATE '. self::tableName .' SET num_checkins=(num_checkins+1), last_updated=NOW()';
		
		$addThis = $this->create_sql_update_string($updateFields, array('session_id' => 'varchar(40)'));
		if(strlen($addThis)) {
			$sql .= ', '. $addThis;
		}
		
		$sql .= ' WHERE session_id=:session_id';
		
		try {
			$retval = $this->db->run_update($sql, $updateFields);
		}
		catch(Exception $e) {
			$message = $e->getMessage() . " --- SQL::: ". $sql . " -- PARAMETERS::: ". strip_tags(ToolBox::debug_print($updateFields,0));
			$this->exception_handler($message);
			$retval = $message;
		}
		
		return($retval);
	}
229889
public function read(/*# string */ $session_id)/*# : string */
    {
        $file = $this->getSessionFile($session_id);
        $content = @file_get_contents($file);
        if (false === $content) {
            $content = 'a:0:{}';
        }
        return $content;
    }
820362
public static function GetInstance($sId)
    {
        $oElement = TdbPkgShopAffiliate::GetNewInstance();
        $oElement->Load($sId);
        if (!empty($oElement->sqlData['class'])) {
            $sClassName = $oElement->sqlData['class'];
            $oElementNew = new $sClassName();
            $oElementNew->LoadFromRow($oElement->sqlData);
            $oElement = $oElementNew;
        }

        return $oElement;
    }
234206
public function read($sessionId) {
        try {
            // try to retrieve the session content first to see if it exists
            $result = $this->_tableRestProxy->getEntity($this->_sessionContainer, $this->_sessionContainerPartition, $sessionId);
            // get the entity instance
            $entity = $result->getEntity();
            // deflat the serialized data
            return unserialize(base64_decode($entity->getPropertyValue('data')));
        } catch (ServiceException $e) {
            // the entity doesn't exist, return empty string according to the spec:
            //   http://www.php.net/manual/en/sessionhandlerinterface.read.php
            return '';
        }
    }
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;
    }
642487
protected function sessionEncode()
    {
        $type = ini_get('session.serialize_handler');
        if ($type === 'php') {
            return $this->serializePHP($this->getSessionState());
        }
        if ($type === 'php_binary') {
            return igbinary_serialize($this->getSessionState());
        }
        return false;
    }
1171665
protected function doRead($sessionId): string
    {
        try {
            $this->sessionDataProvider = $this->getFacade()->get($this->prefix . $sessionId);
        } catch (RedisException $exception) {
            $this->sessionDataProvider->setData('');
        }

        return $this->sessionDataProvider->getData();
    }
200379
public function serverGetPortById($sid)
  {
    if(!array_key_exists((string) $sid, $this->serverList()))
    {
      throw new Exception("invalid serverID", 0x400);
    }

    return $this->serverList[intval((string) $sid)]["virtualserver_port"];
  }
729321
public function current($sid=NULL) {
  if (!isset($sid)) $sid = $this->getSID();
  $query = new \Peyote\Select('sessions');
  $query->columns('user_id')
        ->where('sid', '=', $sid)
        ->limit(1);
  $user = $this->db->fetch($query);
  $user_id = NULL;
  if (isset($user[0]['user_id'])) {
   $user_id = $user[0]['user_id'];
   try {
    $current = $this->get($user_id);
   }
   catch(\Exception $e) {
    if ($e->getCode() == 1200) {
     $current = FALSE;
    }
    else {
     throw new \Exception($e);
    }
   }
   $query = new \Peyote\Update('sessions');
   $query->set([
                'last_access' => date('Y-m-d H:i:s')
               ])
         ->where('sid', '=', $sid);
   $this->db->fetch($query);
  }
  else {
   $current = FALSE;
  }
 return $current;
 }
434553
public function getContext($sid) {
        return new TranscriptionContext(
            $this->version,
            $this->solution['accountSid'],
            $this->solution['recordingSid'],
            $sid
        );
    }
706036
public function read($sessionId)
    {

        if (Config::get('session_user_loc') == 'db') {
            $result = $this->handler->get(Config::get('session_user_loc_table') . '-id-' . $sessionId, true, true, Config::get('session_user_loc_tableprefix'));
            return $result ? $result[0]['value'] : null;
        } else {
            $result = $this->handler->get(Config::get('session_user_loc_tableprefix') . Config::get('session_user_loc_table') . '-id-' . $sessionId);
            return $result ? $result : null;
        }
    }
889365
public function session_exists($sid) {
        if (!$this->connection) {
            return false;
        }

        try {
            return !empty($this->connection->exists($sid));
        } catch (RedisException $e) {
            return false;
        }
    }
357032
function read($id) {
		$this->sid=$id;
		if (!$data=$this->_cache->get($id.'.@'))
			return '';
		if ($data['ip']!=$this->_ip || $data['agent']!=$this->_agent) {
			$fw=Base::instance();
			if (!isset($this->onsuspect) ||
				$fw->call($this->onsuspect,[$this,$id])===FALSE) {
				//NB: `session_destroy` can't be called at that stage (`session_start` not completed)
				$this->destroy($id);
				$this->close();
				unset($fw->{'COOKIE.'.session_name()});
				$fw->error(403);
			}
		}
		return $data['data'];
	}