How can the SERVER_NAME variable in PHP be utilized to generate dynamic URLs within a project?

To generate dynamic URLs within a project, the SERVER_NAME variable in PHP can be utilized by concatenating it with other parts of the URL. This allows for creating URLs that are based on the current server's domain name, making the links dynamic and adaptable to different environments.

$url = 'http://' . $_SERVER['SERVER_NAME'] . '/path/to/page.php';
echo $url;