function getFullURL() { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $domain = $_SERVER['HTTP_HOST']; $path = $_SERVER['REQUEST_URI']; return $protocol . "://" . $domain . $path; } echo getFullURL(); // outputs http://example.com/somepage.php
function getFullURL($page) { $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $domain = $_SERVER['HTTP_HOST']; $path = '/' . ltrim($page, '/'); return $protocol . "://" . $domain . $path; } echo getFullURL('about.php'); // outputs http://example.com/about.phpPackage Library: This function does not require any external package libraries.