Saturday 16 July 2016

PHP Function to get current page URL

Most useful php function in getting the current page url

function getCurrentPageURL() {
    $url = 'http';
    if($_SERVER["HTTPS"] == "on") {

         $url .= "s";
    }
    $url .= "://";
    if($_SERVER["SERVER_PORT"] != "80") {
        $url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
        $url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $url;
}


Use this simple function to get current page url.

No comments:

Post a Comment