From eaba80f68d841f6ccb4cda6b9f4a4a07b5b533fc Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Thu, 19 Mar 2015 11:32:33 +0000 Subject: [PATCH] MDL-49583 enrol: enrol/index.php page doesn't handle direct access well Before this patch if a user who is not logged in to Moodle accesses the enrol/index.php page directly they were redirected to the Moodle front page after login, rather than back to a page that would allow them to self enrol, if it is enabled on the course. This change will cause a user who directly accesses the page to be redirected back to it after they have logged in, unless the course has guest access enabled. Thanks to Marina Glancy for suggesting the use of get_referer() --- enrol/index.php | 6 ++++++ 1 file changed, 6 insertions(+) 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());