Ejemplo n.º 1
0
    public function session_write($sessionid, $sessioncontent)
    {
        $clientid = isset($_SESSION['CurrentState']['Clientid'][0]) && $_SESSION['CurrentState']['Clientid'][0] > 0 ? $_SESSION['CurrentState']['Clientid'][0] : 0;
        $cart = isset($_SESSION['CurrentState']['Cart'][0]) ? $_SESSION['CurrentState']['Cart'][0] : NULL;
        $viewid = isset($_SESSION['CurrentState']['MainsideViewId'][0]) && $_SESSION['CurrentState']['MainsideViewId'][0] > 0 ? $_SESSION['CurrentState']['MainsideViewId'][0] : 0;
        $globalprice = isset($_SESSION['CurrentState']['GlobalPrice'][0]) ? (double) $_SESSION['CurrentState']['GlobalPrice'][0] : 0;
        $cartcurrency = isset($_SESSION['CurrentState']['CurrencySymbol'][0]) ? (string) $_SESSION['CurrentState']['CurrencySymbol'][0] : NULL;
        $ipaddress = isset($_SERVER['REMOTE_ADDR']) ? substr($_SERVER['REMOTE_ADDR'], 0, 15) : '000.000.000.000';
        $browser = isset($_SESSION['CurrentState']['BrowserData'][0]['browser']) && $_SESSION['CurrentState']['BrowserData'][0]['browser'] != '' ? $_SESSION['CurrentState']['BrowserData'][0]['browser'] : NULL;
        $platform = isset($_SESSION['CurrentState']['BrowserData'][0]['platform']) && $_SESSION['CurrentState']['BrowserData'][0]['platform'] != '' ? $_SESSION['CurrentState']['BrowserData'][0]['platform'] : NULL;
        $ismobile = isset($_SESSION['CurrentState']['BrowserData'][0]['ismobile']) && $_SESSION['CurrentState']['BrowserData'][0]['ismobile'] == 1 ? 1 : 0;
        $isbot = isset($_SESSION['CurrentState']['BrowserData'][0]['isbot']) && $_SESSION['CurrentState']['BrowserData'][0]['isbot'] == 1 ? 1 : 0;
        if ($this->isMemcache) {
            $this->registry->cache->save('session_' . $sessionid, $sessioncontent, $this->__SESSION_LIFETIME);
        }
        $sql = 'REPLACE INTO sessionhandler(
					sessioncontent,
					sessionid,
					expiredate,
					clientid,
					globalprice,
					cartcurrency,
					ipaddress,
					browser,
					platform,
					ismobile,
					isbot,
					viewid,
					url,
					cart
				)
				VALUES (
					:sessioncontent,
					:sessionid,
					:expiredate,
					:clientid,
					:globalprice,
					:cartcurrency,
					:ipaddress,
					:browser,
					:platform,
					:ismobile,
					:isbot,
					:viewid,
					:url,
					:cart
				)';
        $stmt = Db::getInstance()->prepare($sql);
        $stmt->bindValue('sessioncontent', $this->isMemcache ? '' : $sessioncontent);
        $stmt->bindValue('sessionid', $sessionid);
        $stmt->bindValue('clientid', $clientid);
        $stmt->bindValue('globalprice', $globalprice);
        $stmt->bindValue('cartcurrency', $cartcurrency);
        $stmt->bindValue('ipaddress', $ipaddress);
        $stmt->bindValue('browser', $browser);
        $stmt->bindValue('cart', json_encode($cart));
        $stmt->bindValue('platform', $platform);
        $stmt->bindValue('url', App::getURL());
        $stmt->bindValue('ismobile', $ismobile);
        $stmt->bindValue('isbot', $isbot);
        if ($viewid > 0) {
            $stmt->bindValue('viewid', $viewid);
        } else {
            $stmt->bindValue('viewid', NULL);
        }
        $stmt->bindValue('expiredate', date('Y-m-d H:i:s', time() + $this->__SESSION_LIFETIME));
        try {
            return $stmt->execute();
        } catch (Exception $e) {
            throw new Exception('Session: write broken while query');
        }
    }