/*
@return $session - Open a session if does not exist in application.
965999
public function getSession() {

		$session = Yii::$app->session;

		if( !$session->isActive ) {

		   $session->open();
		}

		return $session;
	}
624210
public function session() {
		if ($this->session === null) {
			$name = Yesf::app()->getConfig('session.name', Yesf::CONF_ENV, 'YESFSESSID');
			$type = Yesf::app()->getConfig('session.type', Yesf::CONF_ENV, 'cookie');
			$handler = Container::getInstance()->get(Dispatcher::class)->getSessionHandler();
			if ($type === 'cookie') {
				if (!isset($this->cookie[$name])) {
					do {
						$id = Session::generateId();
					} while ($handler->read($id) !== '');
					$saved = '';
					Utils::call($this->cookie_handler, [$name, $id, 0, '/']);
				} else {
					$id = $this->cookie[$name];
					$saved = $handler->read($id);
				}
			} else {
				if (!isset($this->get[$name])) {
					do {
						$id = Session::generateId();
					} while ($handler->read($id) !== '');
					$saved = '';
				} else {
					$id = $this->get[$name];
					$saved = $handler->read($id);
				}
			}
			$this->session = new Session($id, $saved);
		}
		return $this->session;
	}
1361239
public function getSessionFromRedirect()
        {
            $session = $this->getFacebookHelper()->getSessionFromRedirect();

            $this->session->put('session', $session);

            return $session;
        }
1322007
private function hasSession() {

        if(DI::getDefault()->has('session') === true) {

            // get instance of session class
            $this->session = DI::getDefault()->getSession();

            if($this->session->getId() === '') {
                $this->session->start();
            }

            return true;
        }

        return false;
    }
728355
public function getSession($create = false)
    {

        // load the proposed session-ID and name
        $id = $this->getProposedSessionId();
        $sessionName = $this->getRequestedSessionName();

        // if no session has already been load, initialize the session manager
        /** @var \AppserverIo\Appserver\ServletEngine\SessionManagerInterface $manager */
        $manager = $this->getSessionManager();

        // if no session manager was found, we don't support sessions
        if ($manager == null) {
            return;
        }

        // find or create a new session (if flag has been set)
        $session = $manager->find($id);

        // if we can't find a session or session has been expired and we want to create a new one
        if ($session == null && $create === true) {
            // check if a session ID has been specified
            if ($id == null) {
                // if not, generate a unique one
                $id = SessionUtils::generateRandomString();
            }

            // create a new session and register ID in request
            $session = $manager->create($id, $sessionName);
        }

        // if we can't find a session and we should NOT create one, return nothing
        if ($create === false && $session == null) {
            return;
        }

        // if we can't find a session although we SHOULD create one, we throw an exception
        if ($create === true && $session == null) {
            throw new \Exception('Can\'t create a new session!');
        }

        // initialize the session wrapper
        $wrapper = new SessionWrapper();
        $wrapper->injectSession($session);
        $wrapper->injectRequest($this);

        // set the session ID in the execution environment
        Environment::singleton()->setAttribute(EnvironmentKeys::SESSION_ID, $id);

        // return the found session
        return $wrapper;
    }
981883
public function getSession()
    {
        if (!$this->session) {
            /**
             * @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
             */
            $exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
            throw $exception;
        }

        return $this->session;
    }
1277385
public function getSession()
    {
        if (null === $this->requestStack) {
            throw new \RuntimeException('The "app.session" variable is not available.');
        }

        if ($request = $this->getRequest()) {
            return $request->getSession();
        }
    }
1273031
public static function sessionStart()
    {
        if (PHP_SAPI != 'cli') {
            return session_start();
        }

        self::tryGcSessions();

        if (HttpCache::$instance->sessionStarted) {
            echo "already sessionStarted\n";
            return true;
        }
        HttpCache::$instance->sessionStarted = true;
        // Generate a SID.
        if (!isset($_COOKIE[HttpCache::$sessionName]) || !is_file(HttpCache::$sessionPath . '/ses' . $_COOKIE[HttpCache::$sessionName])) {
            $file_name = tempnam(HttpCache::$sessionPath, 'ses');
            if (!$file_name) {
                return false;
            }
            HttpCache::$instance->sessionFile = $file_name;
            $session_id                       = substr(basename($file_name), strlen('ses'));
            return self::setcookie(
                HttpCache::$sessionName
                , $session_id
                , ini_get('session.cookie_lifetime')
                , ini_get('session.cookie_path')
                , ini_get('session.cookie_domain')
                , ini_get('session.cookie_secure')
                , ini_get('session.cookie_httponly')
            );
        }
        if (!HttpCache::$instance->sessionFile) {
            HttpCache::$instance->sessionFile = HttpCache::$sessionPath . '/ses' . $_COOKIE[HttpCache::$sessionName];
        }
        // Read session from session file.
        if (HttpCache::$instance->sessionFile) {
            $raw = file_get_contents(HttpCache::$instance->sessionFile);
            if ($raw) {
                $_SESSION = unserialize($raw);
            }
        }
        return true;
    }
1175395
public function read()
    {
        if (isset($_SESSION[static::SESSION_NAME])) {
            $sess_table = $this->_uncrypt($_SESSION[static::SESSION_NAME]);
            if (isset($sess_table[static::SESSION_ATTRIBUTESNAME])) {
                $this->attributes = $sess_table[static::SESSION_ATTRIBUTESNAME];
            }
        }
        $this->addSessionTable(static::SESSION_ATTRIBUTESNAME, $this->attributes);
        $this->is_loaded = true;
        return $this;
    }
109271
public function createSession()
    {
        $config = $this->app['config']['concrete.session'];
        $storage = $this->getSessionStorage($config);

        // We have to use "build" here because we have bound this classname to this factory method
        $session = $this->app->build(SymfonySession::class, [$storage]);
        $session->setName(array_get($config, 'name'));

        /* @TODO Remove this call. We should be able to set this against the request somewhere much higher than this */
        /*       At the very least we should have an observer that can track the session status and set this */
        $this->app->make(\Concrete\Core\Http\Request::class)->setSession($session);

        return $session;
    }
1142319
public function getSession()
    {
        if (Mage::app()->getStore()->isAdmin()) {
            $session = Mage::getSingleton('adminhtml/session_quote');
        } else {
            $session = Mage::getSingleton('checkout/session');
        }

        return $session;
    }
769634
protected function & getSession () {
		if (isset(self::$allFormsSessions[$this->id])) {
			$sessionNamespace = & self::$allFormsSessions[$this->id];
		} else {
			$sessionClass = self::$sessionClass;
			$toolClass = self::$toolClass;
			$formIdPc = $this->id;
			if (strpos($formIdPc, '-') !== FALSE)
				$formIdPc = $toolClass::GetPascalCaseFromDashed($formIdPc);
			if (strpos($formIdPc, '_') !== FALSE)
				$formIdPc = $toolClass::GetPascalCaseFromUnderscored($formIdPc);
			$namespaceName = '\\MvcCore\\Ext\\Form\\' . ucfirst($formIdPc);
			$sessionNamespace = $sessionClass::GetNamespace($namespaceName);
			// Do not use hoops expiration, because there is better
			// to set up any large value into session namespace
			// or zero value to browser close and after rendered
			// errors just clear the errors.
			//$sessionNamespace->SetExpirationHoops(1);
			$sessionNamespace->SetExpirationSeconds($this->sessionExpiration);
			if (!isset($sessionNamespace->values)) $sessionNamespace->values = [];
			if (!isset($sessionNamespace->csrf)) $sessionNamespace->csrf = [];
			if (!isset($sessionNamespace->errors)) $sessionNamespace->errors = [];
			self::$allFormsSessions[$this->id] = & $sessionNamespace;
		}
		return $sessionNamespace;
	}
163327
function getUserFromPHPSession() {
		if ($this->user == null) {
            $sid = $this->request->session('usersid', '');
            if ($sid == '') {
                // try with a get key
                $sid = $this->request->get('sessionid', '');
            }
			$this->user = $this->getUserFromSession($sid);
		}
        return $this->user;
    }
1115504
public function getSession()
    {
        if ($this->_session === false) {
            $sessionId = is_callable($this->sessionKey) ? call_user_func($this->sessionKey,
                $this) : $this->headers->first($this->sessionKey);
            if ($session = session()->get($sessionId)) {
                $this->_session = $session;
            } else {
                $this->_session = null;
            }
        }

        return $this->_session;
    }
19992
protected function loadSession()
    {
        if (session_id() === '') {
            session_start();
        }

        $value = \Slim\Http\Util::decodeSecureCookie(
            $this->app->request()->cookies($this->settings['name']),
            $this->settings['secret'],
            $this->settings['cipher'],
            $this->settings['cipher_mode']
        );
        if ($value) {
            $_SESSION = unserialize($value);
        } else {
            $_SESSION = array();
        }
    }
960970
public static function getSession()
    {
        if (is_null(self::$session)) {
            if (PHPSession::singleton()->hasAttribute(self::PHPSESSION_SESSION_KEY)) {
                $session = PHPSession::singleton()->getAttribute(self::PHPSESSION_SESSION_KEY);
                if (! $session instanceof common_session_Session) {
                    throw new common_exception_Error('Non session stored in php-session');
                }
                self::$session = $session;
            } else {
                self::$session = new common_session_AnonymousSession();
            }
        }
        if (self::$session instanceof ServiceLocatorAwareInterface) {
            self::$session->setServiceLocator(ServiceManager::getServiceManager());
        }
        return self::$session;
    }
337267
public function Start() {
		if ($this->triedstart) {
			return $this->triedresult;
		}
		BLog::addToLog('[Users.Session]: Start()');
		$this->triedresult = false;
		$this->triedstart = true;
		$secret = explode(':', $_COOKIE['brillsecret']);
		if (count($secret) < 2) {
			$this->triedresult = false;
			return false;
		}
		$bCache = BFactory::getCache();
		if (!empty($bCache)) {
			$sess = $bCache->get('session:' . $secret[1]);
			if (($sess !== false) && ($sess !== NULL)) {
				$this->load($sess);
				$this->triedresult = true;
				return true;
			}
		}
		$db = BFactory::getDBO();
		if (empty($db)) {
			return false;
		}
		$qr = 'SELECT * from `sessions` WHERE (sessionid=' . $db->escapeString($secret[1]) . '&&userid=' . (int)$secret[0] . ')';
		$q = $db->Query($qr);
		if (empty($q)) {
			if (DEBUG_MODE) {
				BLog::addToLog('[Session]: Could not execute query! MySQL error: ' . $db->lasterror(), LL_ERROR);
			}
			return false;
		}
		$l = $db->fetch($q);
		if (empty($l)) {
			setcookie('brillsecret', '', time(), '/', BHOSTNAME);
			return false;
		}
		if (!empty($bCache)) {
			$bCache->set('session:' . $l['sessionid'], $l, 600);
		}
		$this->load($l, true);
		$this->triedstart = true;
		$this->triedresult = true;
		return true;
	}