Browse Source

default to file-based session storage

Andrew Dolgov 2 years ago
parent
commit
f25abeb922
5 changed files with 15 additions and 4 deletions
  1. 1 0
      .gitignore
  2. 2 0
      config.php-dist
  3. 4 0
      index.php
  4. 8 4
      sessions.php
  5. 0 0
      sessions/.empty

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 config.php
 db/scratch.db
+sessions/sess*

+ 2 - 0
config.php-dist

@@ -9,3 +9,5 @@
 	define('DICT_CLIENT', '/usr/bin/dict');
 	define('DICT_SERVER', 'localhost');
 
+	define('SQLITE_SESSION_STORE', false);
+	// store sessions in scratch.db (not recommended, slow)

+ 4 - 0
index.php

@@ -3,6 +3,10 @@
 		die("Please copy config.php-dist to config.php and edit it.");
 	}
 
+	if (!is_writable("sessions")) {
+		die("sessions/ directory is not writable.");
+	}
+
 	if (isset($_SERVER["PHP_AUTH_USER"])) {
 		die("HTTP Authentication is no longer supported, please see migration notes in git.");
 	}

+ 8 - 4
sessions.php

@@ -57,12 +57,16 @@
 
 		return true;
 	}
-	session_set_save_handler("s_open",
-		"s_close", "s_read", "s_write",
-		"s_destroy", "s_gc");
+
+	if (defined('SQLITE_SESSION_STORE') && SQLITE_SESSION_STORE) {
+		session_set_save_handler("s_open",
+			"s_close", "s_read", "s_write",
+			"s_destroy", "s_gc");
+	} else {
+		session_save_path(__DIR__ . "/sessions");
+	}
 
 	register_shutdown_function('session_write_close');
 
 	session_start();
-
 ?>

+ 0 - 0
sessions/.empty