How can you handle cases where the referer is not set when trying to identify the subdomain in PHP?

When the referer is not set, you can still identify the subdomain by parsing the current URL. You can use the $_SERVER['HTTP_HOST'] variable to get the full domain and then extract the subdomain from it. This can be achieved by splitting the domain into an array and getting the first element.

$domain = $_SERVER['HTTP_HOST'];
$subdomain = explode('.', $domain)[0];
echo $subdomain;