Skip to content

Commit 1035d37

Browse files
committed
Refactor finding server host name for urls
HTTP_HOST is empty/blank on FastCGI over QUIC
1 parent cacb83d commit 1035d37

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Libraries/Core/Router.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,12 @@ public static function query(): array
176176
self::$args = \array_merge($url_args, $body_args);
177177
return self::$args;
178178
}
179+
180+
public static function serverName(): string
181+
{
182+
$name = \getenv('HTTP_HOST') ?? '';
183+
if (empty($name)) $name = \getenv('SERVER_NAME') ?? '';
184+
if (empty($name)) $name = \getenv('HOST') ?? '';
185+
return $name ?? '';
186+
}
179187
}

src/Libraries/Core/UrlFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public static function format(string $value): string
3232

3333
// Current request
3434
$current_scheme = 'http' . ($secure ? 's' : '') . ':';
35-
$current_host = \getenv('HTTP_HOST');
36-
$current_path = \getenv('DOCUMENT_URI');
37-
$current_query = \getenv('QUERY_STRING');
35+
$current_host = \BNETDocs\Libraries\Core\Router::serverName();
36+
$current_path = \getenv('DOCUMENT_URI') ?? '';
37+
$current_query = \getenv('QUERY_STRING') ?? '';
3838

3939
// Placeholders
4040
$scheme = null;

src/Templates/EventLog/View.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ if (!empty($tpl_referer))
6161
{
6262
$tpl_referer = '<a href="' . filter_var($tpl_referer, FILTER_SANITIZE_FULL_SPECIAL_CHARS) . '">&lt;&lt; Back to Previous</a>';
6363
}
64-
if (stripos($tpl_referer, getenv('HTTP_HOST')) === false)
64+
if (stripos($tpl_referer, \BNETDocs\Libraries\Core\Router::serverName()) === false)
6565
{
6666
$tpl_referer = '';
6767
}

0 commit comments

Comments
 (0)