Respect HTTP_X_FORWARDED_HOST

alongside _PORT and _PROTO
Fixes #879
This commit is contained in:
Stephen Muth 2017-07-08 00:01:03 +00:00
parent 70cb883547
commit b80315e238
1 changed files with 13 additions and 1 deletions

View File

@ -311,7 +311,19 @@ function server_url($server)
}
}
return $scheme.'://'.$server['SERVER_NAME'].$port;
if (isset($server['HTTP_X_FORWARDED_HOST'])) {
// Keep forwarded host
if (strpos($server['HTTP_X_FORWARDED_HOST'], ',') !== false) {
$hosts = explode(',', $server['HTTP_X_FORWARDED_HOST']);
$host = trim($hosts[0]);
} else {
$host = $server['HTTP_X_FORWARDED_HOST'];
}
} else {
$host = $server['SERVER_NAME'];
}
return $scheme.'://'.$host.$port;
}
// SSL detection