MDL-34965 core_lib Redirect to the login page when session expires before autologin...
authorDavid Monllao <davidm@moodle.com>
Mon, 20 Aug 2012 04:10:34 +0000 (12:10 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 28 Aug 2012 00:58:59 +0000 (08:58 +0800)
lib/moodlelib.php

index 55cfd1f..646c1eb 100644 (file)
@@ -2775,6 +2775,14 @@ function require_login($courseorid = NULL, $autologinguest = true, $cm = NULL, $
         $setwantsurltome = false;
     }
 
+    // Redirect to the login page if session has expired, only with dbsessions enabled (MDL-35029) to maintain current behaviour.
+    if (!empty($SESSION->has_timed_out) && !$preventredirect && !empty($CFG->dbsessions)) {
+        if ($setwantsurltome) {
+            $SESSION->wantsurl = qualified_me();
+        }
+        redirect(get_login_url());
+    }
+
     // If the user is not even logged in yet then make sure they are
     if (!isloggedin()) {
         if ($autologinguest and !empty($CFG->guestloginbutton) and !empty($CFG->autologinguests)) {