Current URL with PHP (PHP)

by spyka (http://www.spyka.net)

You can use this simple function to get the current URL of the page. Example usage is shown below and in demo

Code:
<?
function getCurrentPage() {
        
$domain .= "http://";
    
$domain .= $_SERVER['HTTP_HOST'];
    
$domain .= $_SERVER['REQUEST_URI'];
    return 
$domain;
}

echo 
"The current URL is: ".getCurrentPage()."!";
?>

Code demo

Current URL with PHP online demo

Help and comments

Discuss this and other scripts in our webmaster foruns

Learn more about our forums