|
|
@@ -17,10 +17,14 @@ class Session extends Model {
|
|
|
/**
|
|
|
* @param string $name
|
|
|
* @param int $timeout
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
|
public static function start(string $name = "", int $timeout = 3600) {
|
|
|
|
|
|
$handler = new SiteSessionHandler();
|
|
|
+
|
|
|
+ self::gc($handler);
|
|
|
+
|
|
|
session_set_save_handler($handler, true);
|
|
|
|
|
|
session_set_cookie_params($timeout, "/", "");
|
|
|
@@ -40,4 +44,18 @@ class Session extends Model {
|
|
|
setcookie($name, $id, time() + $timeout, "/", "");
|
|
|
}
|
|
|
|
|
|
+ public static function gc(SessionHandlerInterface $handler) {
|
|
|
+ try {
|
|
|
+ if(defined("SESSION_GC_LIFETIME") && defined("SESSION_GC_PROBABILITY")) {
|
|
|
+ $random_int = rand(0, 999);
|
|
|
+ if($random_int < SESSION_GC_PROBABILITY) {
|
|
|
+ $handler->gc(SESSION_GC_LIFETIME);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|