From 4b4e06a98f0f01695bda18de240bb3294d096ef4 Mon Sep 17 00:00:00 2001 From: Joey Kimsey Date: Tue, 21 Jan 2025 20:43:15 -0500 Subject: [PATCH] Improved http vs https detection To fix issues with cloudflare dns routing. --- functions/route.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/functions/route.php b/functions/route.php index 22227b4..d5be5bf 100644 --- a/functions/route.php +++ b/functions/route.php @@ -43,10 +43,16 @@ class Route { * @return string - The string representation of the server's transfer protocol */ public static function getProtocol() { - if ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) { + if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') { return 'https'; } - if ( $_SERVER['SERVER_PORT'] == 443 ) { + if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { + return 'https'; + } + if (!empty($_SERVER['HTTP_X_FORWARDED_PORT']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == 443) { + return 'https'; + } + if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { return 'https'; } return 'http';