This commit is contained in:
Dennis Eichhorn 2017-09-05 13:18:52 +02:00 committed by GitHub
parent 0339d8ad44
commit 6a4024d24e

View File

@ -55,17 +55,26 @@ class HttpSession implements SessionInterface
*/ */
private $sid = null; private $sid = null;
/**
* Inactivity Interval.
*
* @var int
* @since 1.0.0
*/
private $inactivityInterval = 0;
/** /**
* Constructor. * Constructor.
* *
* @param int $liftetime Session life time * @param int $liftetime Session life time
* @param string|int|bool $sid Session id * @param string|int|bool $sid Session id
* @param int $inactivityInterval Interval for session activity
* *
* @throws LockException Throws this exception if the session is alrady locked for further interaction. * @throws LockException Throws this exception if the session is alrady locked for further interaction.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct(int $liftetime = 3600, $sid = false) public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0)
{ {
if (self::$isLocked) { if (self::$isLocked) {
throw new LockException('HttpSession'); throw new LockException('HttpSession');
@ -75,12 +84,20 @@ class HttpSession implements SessionInterface
session_id($sid); session_id($sid);
} }
$this->inactivityInterval = $inactivityInterval;
session_set_cookie_params($liftetime, '/', '', false, true); session_set_cookie_params($liftetime, '/', '', false, true);
session_start(); session_start();
if($this->inactivityInterval > 0 && ($this->inactivityInterval + ($_SESSION['lastActivity'] ?? 0) < time())) {
$this->destroy();
}
$this->sessionData = $_SESSION; $this->sessionData = $_SESSION;
$_SESSION = null; $_SESSION = null;
$this->sessionData['lastActivity'] = time();
$this->sid = session_id(); $this->sid = session_id();
$this->setCsrfProtection(); $this->setCsrfProtection();
} }
@ -186,6 +203,12 @@ class HttpSession implements SessionInterface
$this->sid = $sid; $this->sid = $sid;
} }
private function destroy() /* : void */
{
session_destroy();
session_start();
}
/** /**
* Destruct session. * Destruct session.
* *