diff --git a/enrol/index.php b/enrol/index.php index 2fdff2a44ab60..7969859c0d1c2 100644 --- a/enrol/index.php +++ b/enrol/index.php @@ -28,6 +28,12 @@ $id = required_param('id', PARAM_INT); if (!isloggedin()) { + $referer = clean_param(get_referer(), PARAM_LOCALURL); + if (empty($referer)) { + // A user that is not logged in has arrived directly on this page, + // they should be redirected to the course page they are trying to enrol on after logging in. + $SESSION->wantsurl = "$CFG->wwwroot/course/view.php?id=$id"; + } // do not use require_login here because we are usually coming from it, // it would also mess up the SESSION->wantsurl redirect(get_login_url());