コード例 #1
0
 function &createSession($create = TRUE)
 {
     if (ServletContext::validClass($this->context)) {
         $response =& $this->context->getServletResponse();
         $session =& $this->context->getServletSession();
         if (IHttpResponse::validClass($response) && IHttpSession::validClass($session)) {
             $sessionid = '';
             $cookie = $this->getCookie('_JPHPSESSIONID');
             if (!isset($cookie)) {
                 $sessionid = $this->getParameter('_JPHPSESSIONID');
             } else {
                 $sessionid = $cookie->getValue();
             }
             if (strlen(trim($sessionid)) < 8) {
                 if ($create == FALSE) {
                     return NULL;
                 } else {
                     $sessionid = md5(StringBuffer::generateKey(16));
                 }
             }
             $session->setSessionID($sessionid);
             $session->initialize();
             $cookie = new Cookie('_JPHPSESSIONID', $sessionid);
             if ($session->getMaxInactiveInterval() > 0) {
                 $cookie->setMaxAge(time() + $session->getMaxInactiveInterval());
             } else {
                 $cookie->setMaxAge(0);
             }
             $response->addCookie($cookie);
             return $session;
         }
     }
     return NULL;
 }
コード例 #2
0
ファイル: HttpSession.php プロジェクト: alexpagnoni/jphp
 function initialize()
 {
     // path existance
     if (!file_exists($this->path)) {
         if (!$this->createStructure($this->path)) {
             die('I/O Exception : ' . $this->path . ' cannot be create ...');
         }
     } else {
         if (!is_dir($this->path)) {
             die('I/O Exception : ' . $this->path . ' exists and it\' a file ...');
         }
     }
     // load session object
     if (isset($this->sessionID)) {
         if (!file_exists($this->path . $this->sessionID . '.cache')) {
             $this->cache = array();
             $this->creationTime = time();
             $this->lastAccessedTime = $this->creationTime;
             $this->isNewSession = TRUE;
             $this->saveSessionObject();
         } else {
             if (!$this->loadSessionObject()) {
                 $this->sessionID = md5(StringBuffer::generateKey(16));
                 $this->cache = array();
                 $this->creationTime = time();
                 $this->lastAccessedTime = $this->creationTime;
                 $this->isNewSession = TRUE;
                 $this->saveSessionObject();
             }
         }
     }
 }