/** * Initialize session. * Set cookie path to path to current URI without file. * * @throw Exception if cannot start session */ public static function start() { if (!self::$session_created) { $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // remove file name from path $path = substr($path, 0, strrpos($path, '/') + 1); ob_start(); session_set_cookie_params(0, $path, null, HTTPS); if (!session_start()) { throw new Exception('Cannot start session.'); } session_write_close(); ob_flush(); self::$session_created = true; } }