/** * insert new session * * @access public * @return mixed Session ID if success, otherwise Jaws_Error or false */ function insert() { $max_active_sessions = (int) $GLOBALS['app']->Registry->fetch('max_active_sessions', 'Policy'); if (!empty($max_active_sessions)) { $activeSessions = $this->GetSessionsCount(true); if ($activeSessions >= $max_active_sessions) { // remove expired session $this->DeleteExpiredSessions(); $GLOBALS['app']->Session->Logout(); Jaws_Error::Fatal(_t('GLOBAL_HTTP_ERROR_CONTENT_503_OVERLOAD'), 0, 503); } } // agent $agent = substr(Jaws_XSS::filter($_SERVER['HTTP_USER_AGENT']), 0, 252); // ip $ip = 0; if (preg_match('/\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b/', $_SERVER['REMOTE_ADDR'])) { $ip = ip2long($_SERVER['REMOTE_ADDR']); $ip = $ip < 0 ? $ip + 0xffffffff + 1 : $ip; } // referrer $referrer = Jaws_Utils::getHostReferrer(); $sessTable = Jaws_ORM::getInstance()->table('session', '', 'sid'); if (!empty($GLOBALS['app']->Session->_Attributes)) { //A new session, we insert it to the DB $updatetime = time(); $user = $GLOBALS['app']->Session->GetAttribute('user'); $serialized = serialize($GLOBALS['app']->Session->_Attributes); $sessTable->insert(array('user' => $user, 'type' => JAWS_APPTYPE, 'longevity' => $GLOBALS['app']->Session->GetAttribute('longevity'), 'data' => $serialized, 'referrer' => md5($referrer), 'checksum' => md5($user . $serialized), 'ip' => $ip, 'agent' => $agent, 'createtime' => $updatetime, 'updatetime' => $updatetime)); $result = $sessTable->exec(); if (!Jaws_Error::IsError($result)) { return $result; } } return false; }