From 29857e7d705cd0c6bd4cd4f9fb7616760b4d6c36 Mon Sep 17 00:00:00 2001 From: "Martin N." Date: Mon, 1 Dec 2014 16:45:49 +0100 Subject: [PATCH] Using a custom session_start_safe This fixes path issues, where the session directory ends up not writeable. --- lib/settings-common.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/settings-common.php b/lib/settings-common.php index b81b1a9..d620a96 100644 --- a/lib/settings-common.php +++ b/lib/settings-common.php @@ -15,12 +15,30 @@ $context = stream_context_create(array('http'=> ) )); +// sets up a session, either with the local tmp directory or with the default directory +function session_start_safe() { + // Trying with the local path + session_save_path(dirname(__FILE__).'/../tmp'); + session_start(); + if(!$_SESSION['working']) $_SESSION['working'] = true; + session_write_close(); + unset($_SESSION); + // Let's see if that worked + session_start(); + if($_SESSION['working']) { + unset($_SESSION['working']); + return; // we've got a working session + } else { + // Create a new session with the default path. + session_destroy(); + session_save_path(''); + session_start(); + } +} + // Start a session if we haven't already if(!isset($_SESSION)) { - session_save_path(dirname(__FILE__).'/../tmp'); - // Make the session cookie HTTP only - session_set_cookie_params(0, '/', '', false, true); - @session_start(); + session_start_safe(); } // Set the language file, if now possible