How can the complete URI be accessed in PHP, including the server name and request URI?

To access the complete URI in PHP, including the server name and request URI, you can use the combination of $_SERVER['HTTP_HOST'] and $_SERVER['REQUEST_URI'] variables. By concatenating these two variables, you can get the complete URI.

$serverName = $_SERVER['HTTP_HOST'];
$requestURI = $_SERVER['REQUEST_URI'];
$completeURI = "http://$serverName$requestURI";
echo $completeURI;