From df92ba9a43713e1c901ac29c3f73f8814a30affb Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 16 Aug 2010 17:47:36 +0000 Subject: [PATCH] MDL-23797 minor session refactoring necessary for setting of default context on pages that do not use cookies --- lib/sessionlib.php | 12 ------------ lib/setup.php | 14 ++++++++++++++ lib/setuplib.php | 4 +++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/sessionlib.php b/lib/sessionlib.php index 65a18f2b459..6444a91256d 100644 --- a/lib/sessionlib.php +++ b/lib/sessionlib.php @@ -99,18 +99,6 @@ abstract class session_stub implements moodle_session { public function __construct() { global $CFG; - if (!defined('NO_MOODLE_COOKIES')) { - if (empty($CFG->version) or $CFG->version < 2009011900) { - // no session before sessions table gets created - define('NO_MOODLE_COOKIES', true); - } else if (CLI_SCRIPT) { - // CLI scripts can not have session - define('NO_MOODLE_COOKIES', true); - } else { - define('NO_MOODLE_COOKIES', false); - } - } - if (NO_MOODLE_COOKIES) { // session not used at all $CFG->usesid = 0; diff --git a/lib/setup.php b/lib/setup.php index 1fb7796a6a8..31b2e8e572f 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -584,6 +584,20 @@ if (isset($_SERVER['PHP_SELF'])) { // initialise ME's initialise_fullme(); + +// init session prevention flag - this is defined on pages that do not want session +if (!defined('NO_MOODLE_COOKIES')) { + if (empty($CFG->version) or $CFG->version < 2009011900) { + // no session before sessions table gets created + define('NO_MOODLE_COOKIES', true); + } else if (CLI_SCRIPT) { + // CLI scripts can not have session + define('NO_MOODLE_COOKIES', true); + } else { + define('NO_MOODLE_COOKIES', false); + } +} + // start session and prepare global $SESSION, $USER session_get_instance(); $SESSION = &$_SESSION['SESSION']; diff --git a/lib/setuplib.php b/lib/setuplib.php index 0ae277cab66..b67cc77128e 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -540,7 +540,9 @@ function initialise_fullme() { if (($rurl['host'] != $wwwroot['host']) or (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) { // Explain the problem and redirect them to the right URL - define('NO_MOODLE_COOKIES', true); + if (!defined('NO_MOODLE_COOKIES')) { + define('NO_MOODLE_COOKIES', true); + } redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); } }