diff --git a/course/loginas.php b/course/loginas.php index cc55ae042ac..f72175fcea9 100644 --- a/course/loginas.php +++ b/course/loginas.php @@ -4,9 +4,10 @@ require_once("../config.php"); require_once("lib.php"); - require_variable($id); // course id + require_variable($id); // course id optional_variable($user); // login as this user - optional_variable($return); // return to being the real user again + optional_variable($return); // return to the page we came from + if (! $course = get_record("course", "id", $id)) { error("Course ID was incorrect"); @@ -16,7 +17,7 @@ require_login($course->id); } - if ($return and $USER->realuser) { + if ($USER->realuser) { /// Reset user back to their real self $USER = get_user_info_from_db("id", $USER->realuser); $USER->loggedin = true; $USER->site = $CFG->wwwroot; @@ -30,8 +31,10 @@ unset($SESSION->oldtimeaccess); } - redirect($_SERVER["HTTP_REFERER"]); - exit; + if ($return) { /// That's all we wanted to do, so let's go back + redirect($_SERVER["HTTP_REFERER"]); + exit; + } } // $user must be defined to go on