* [refac] Refactor the baseRouter::startSession() method to reuse web session in api mode.
This commit is contained in:
@@ -848,13 +848,6 @@ class baseHelper
|
||||
if(empty($sessionID)) $sessionID = sha1((string)mt_rand(0, mt_getrandmax()));
|
||||
|
||||
session_write_close();
|
||||
|
||||
if(ini_get('session.save_handler') == 'user')
|
||||
{
|
||||
$ztSessionHandler = new ztSessionHandler();
|
||||
session_set_save_handler($ztSessionHandler, true);
|
||||
}
|
||||
|
||||
session_id($sessionID);
|
||||
session_start();
|
||||
|
||||
|
||||
@@ -1196,7 +1196,7 @@ class baseRouter
|
||||
if(defined('SESSION_STARTED')) return;
|
||||
|
||||
/* API session use tmp/apisession directory. */
|
||||
$apiMode = (defined('RUN_MODE') && RUN_MODE == 'api') || isset($_GET[$this->config->sessionVar]);
|
||||
$apiMode = (defined('RUN_MODE') && RUN_MODE == 'api') && !isset($_GET[$this->config->sessionVar]);
|
||||
|
||||
if(ini_get('session.save_handler') == 'files' || $apiMode)
|
||||
{
|
||||
@@ -1217,18 +1217,17 @@ class baseRouter
|
||||
session_set_cookie_params(0, $this->config->webRoot, '', $this->config->cookieSecure, true);
|
||||
if(!session_id()) session_start();
|
||||
|
||||
$this->sessionID = isset($ztSessionHandler) ? $ztSessionHandler->getSessionID() : session_id();
|
||||
|
||||
if(isset($_SERVER['HTTP_TOKEN'])) // If request header has token, use it as session for authentication.
|
||||
{
|
||||
helper::restartSession($_SERVER['HTTP_TOKEN']);
|
||||
$this->sessionID = isset($ztSessionHandler) ? $ztSessionHandler->getSessionID() : session_id();
|
||||
}
|
||||
elseif(isset($_GET[$this->config->sessionVar]))
|
||||
{
|
||||
helper::restartSession($_GET[$this->config->sessionVar]);
|
||||
}
|
||||
|
||||
$this->sessionID = isset($ztSessionHandler) ? $ztSessionHandler->getSessionID() : session_id();
|
||||
|
||||
define('SESSION_STARTED', true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user