Commit 8a09de28 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow login redirect to subdomains (bug #1006634)

When a page at a user subdomain such as http://bob.example.com/my-page
is requested by a logged out user, ensure that the user is redirected
to a login page that works, rather than to http://example.com/my-page

.

Because the existing get_full_script_path() function is currently
unused, this function is modified to call get_requested_host_name(),
and then used in the AccessDeniedException for the login form
redirect.

Change-Id: I182adeb1a83363512dfde638f2aad23b1d69bcb4
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent a051dc34
......@@ -891,7 +891,7 @@ class AccessDeniedException extends UserException {
public function render_exception() {
global $USER;
if (defined('PUBLIC') && !$USER->is_logged_in()) {
$loginurl = substr($_SERVER['REQUEST_URI'], strlen(get_mahara_install_subdirectory()) - 1);
$loginurl = get_full_script_path();
$loginurl .= (false === strpos($loginurl, '?')) ? '?' : '&';
$loginurl .= 'login';
redirect($loginurl);
......
......@@ -2619,18 +2619,7 @@ function get_full_script_path() {
$url = parse_url($CFG->wwwroot);
}
if (!empty($url['host'])) {
$hostname = $url['host'];
} else if (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
} else if (!empty($_ENV['SERVER_NAME'])) {
$hostname = $_ENV['SERVER_NAME'];
} else if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
} else if (!empty($_ENV['HTTP_HOST'])) {
$hostname = $_ENV['HTTP_HOST'];
} else {
log_warn('Warning: could not find the name of this server!');
if (!$hostname = get_requested_host_name()) {
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment