What are the potential limitations of using $_SERVER variables to extract subdomains in PHP?

Using $_SERVER variables to extract subdomains in PHP can be limited because it relies on the server configuration and may not work consistently across different environments. To ensure more reliable subdomain extraction, it's recommended to use the parse_url() function to parse the URL and extract the subdomain from the host.

$url = 'http://subdomain.example.com';
$host = parse_url($url, PHP_URL_HOST);
$subdomain = explode('.', $host)[0];
echo $subdomain; // Output: subdomain