Welcome Guest, Not a member yet? Register   Sign In
getting $host from $_SERVER
#1

As part of something else, I have a very small site running on a raspberry pi (apache2.4.38, php8.1.15) and normally it works perfectly but sometimes the log file shows a crash on config/constants. I tracked it down to the following:
PHP Code:
$host $_SERVER['HTTP_HOST'];
   
$http_https = isset($_SERVER['HTTPS']) ? "https://" "http://";
   
$baseURL $http_https $host;
   
define('BASE_URL',$baseURL); 
I have set htaccess to force https. Sometimes when the site is accessed, don't know why, HTTP_HOST is missing from $_SERVER. The HTTPS key is also missing. Maybe in order to make Constants.php bullet-proof it would be good to have a fallback eg
PHP Code:
if(array_key_exists('HTTP_HOST',$_SERVER)) $host $_SERVER['HTTP_HOST'];
   else 
$host=$_SERVER['SERVER_NAME']; 

Bill
Reply


Messages In This Thread
getting $host from $_SERVER - by badger - 02-26-2023, 08:25 AM
RE: getting $host from $_SERVER - by Gary - 02-26-2023, 11:02 AM
RE: getting $host from $_SERVER - by badger - 02-26-2023, 11:20 AM
RE: getting $host from $_SERVER - by kenjis - 02-26-2023, 07:17 PM
RE: getting $host from $_SERVER - by badger - 02-27-2023, 02:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB