diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 3cbd8604a5b..d78d3de4bfc 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2057,7 +2057,12 @@ function require_logout() { error_log('MoodleSessionTest cookie could not be set in moodlelib.php:'.__LINE__); error_log('Headers were already sent in file: '.$file.' on line '.$line); } else { - setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + if (function_exists('array_fill_keys')) { + //PHP 5.2.0 + setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + } else { + setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure); + } } unset($_SESSION['USER']); @@ -7751,8 +7756,14 @@ function report_session_error() { moodle_setlocale(); //clear session cookies - setcookie('MoodleSession'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); - setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + if (function_exists('array_fill_keys')) { + //PHP 5.2.0 + setcookie('MoodleSession'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + } else { + setcookie('MoodleSession'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure); + setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, $CFG->sessioncookiepath, '', $CFG->cookiesecure); + } //increment database error counters if (isset($CFG->session_error_counter)) { set_config('session_error_counter', 1 + $CFG->session_error_counter); diff --git a/lib/setup.php b/lib/setup.php index 6b0a2c8d022..0923afb4576 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -517,7 +517,12 @@ global $HTTPSPAGEREQUIRED; if (empty($nomoodlecookie)) { session_name('MoodleSession'.$CFG->sessioncookie); - session_set_cookie_params(0, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + if (function_exists('array_fill_keys')) { + //PHP 5.2.0 + session_set_cookie_params(0, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + } else { + session_set_cookie_params(0, $CFG->sessioncookiepath, '', $CFG->cookiesecure); + } @session_start(); if (! isset($_SESSION['SESSION'])) { $_SESSION['SESSION'] = new object; @@ -525,7 +530,12 @@ global $HTTPSPAGEREQUIRED; if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) { $_SESSION['SESSION']->has_timed_out = true; } - setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + if (function_exists('array_fill_keys')) { + //PHP 5.2.0 + setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, $CFG->sessioncookiepath, '', $CFG->cookiesecure, $CFG->cookiehttponly); + } else { + setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, $CFG->sessioncookiepath, '', $CFG->cookiesecure); + } $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] = $_SESSION['SESSION']->session_test; } if (! isset($_SESSION['USER'])) {