You are here

public function SessionProxy_Backend_Base::commit in Session Proxy 7

Called during shutdown hook time, this allows you to perform additional operations outside of the core PHP session handling at the end of request.

Overrides SessionProxy_Backend_Interface::commit

File

lib/SessionProxy/Backend/Base.php, line 152

Class

SessionProxy_Backend_Base

Code

public function commit() {
  global $user;
  if (!$this
    ->isWriteEnabled()) {
    return;
  }
  if ($user->uid) {

    // Always save logged in user sessions: we will let the underlaying
    // storage engine decide weither or not data should really be saved.
    session_write_close();
  }
  else {
    if (!empty($_SESSION)) {

      // Save session for anonymous only if session data has been se: this
      // is another lazzy session creation feature artifact.
      if (!$this->started) {
        $this
          ->start();
      }
      session_write_close();
    }
    else {

      // Drop anonymous session
      if ($this
        ->isStarted()) {
        $this
          ->destroy();
      }
    }
  }
}