What are best practices for dynamically handling different content based on the domain accessed in PHP?

When dynamically handling different content based on the domain accessed in PHP, one common approach is to use the $_SERVER['HTTP_HOST'] variable to determine the domain being accessed and then use conditional statements to load the appropriate content based on that domain.

<?php

$domain = $_SERVER['HTTP_HOST'];

if ($domain == 'example.com') {
    // Load content specific to example.com
    echo "Welcome to example.com!";
} elseif ($domain == 'anotherdomain.com') {
    // Load content specific to anotherdomain.com
    echo "Welcome to anotherdomain.com!";
} else {
    // Default content for other domains
    echo "Welcome to our website!";
}

?>