diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 32e0234bf3d92..cc6bd768b78ed 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2727,11 +2727,6 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ $SESSION->wantsurl = qualified_me(); } - $referer = get_local_referer(false); - if (!empty($referer)) { - $SESSION->fromurl = $referer; - } - // Give auth plugins an opportunity to authenticate or redirect to an external login page $authsequence = get_enabled_auth_plugins(); // Auths, in sequence. foreach($authsequence as $authname) { diff --git a/lib/setuplib.php b/lib/setuplib.php index 2af28136af9b8..f1ad98d70aed5 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -588,12 +588,7 @@ function get_exception_info($ex) { $moreinfourl = $errordoclink . 'error/' . $modulelink . '/' . $errorcode; if (empty($link)) { - if (!empty($SESSION->fromurl)) { - $link = $SESSION->fromurl; - unset($SESSION->fromurl); - } else { - $link = $CFG->wwwroot .'/'; - } + $link = get_local_referer(false) ?: ($CFG->wwwroot . '/'); } // When printing an error the continue button should never link offsite. diff --git a/lib/tests/setuplib_test.php b/lib/tests/setuplib_test.php index 9291605e9cde4..9d165b99dd7e0 100644 --- a/lib/tests/setuplib_test.php +++ b/lib/tests/setuplib_test.php @@ -412,32 +412,6 @@ public function test_get_exception_info_link() { $exception = new moodle_exception('none', 'error', $url); $infos = $this->get_exception_info($exception); $this->assertSame($CFG->wwwroot . '/', $infos->link); - - // Internal link from fromurl. - $SESSION->fromurl = $url = $CFG->wwwroot . '/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($url, $infos->link); - - // Internal HTTPS link from fromurl. - $SESSION->fromurl = $url = $httpswwwroot . '/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($url, $infos->link); - - // External link from fromurl. - $SESSION->fromurl = 'http://moodle.org/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($CFG->wwwroot . '/', $infos->link); - - // External HTTPS link from fromurl. - $SESSION->fromurl = 'https://moodle.org/something/here?really=yes'; - $exception = new moodle_exception('none'); - $infos = $this->get_exception_info($exception); - $this->assertSame($CFG->wwwroot . '/', $infos->link); - - $SESSION->fromurl = ''; } /** diff --git a/mod/forum/post.php b/mod/forum/post.php index 7d9e3abc28834..ae162ebfa75a2 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -160,8 +160,6 @@ ); } - $SESSION->fromurl = get_local_referer(false); - // Load up the $post variable. $post = new stdClass(); @@ -780,11 +778,7 @@ } } else if ($mformpost->is_submitted() && !$mformpost->no_submit_button_pressed() && $fromform = $mformpost->get_data()) { - if (empty($SESSION->fromurl)) { - $errordestination = $urlfactory->get_forum_view_url_from_forum($forumentity); - } else { - $errordestination = $SESSION->fromurl; - } + $errordestination = get_local_referer(false) ?: $urlfactory->get_forum_view_url_from_forum($forumentity); $fromform->itemid = $fromform->message['itemid']; $fromform->messageformat = $fromform->message['format'];