HomeCoding & Programming

PHP function to get current web page full URL

Like Tweet Pin it Share Share Email

PHP function to get current web page full URL & current page name.

Sometimes, you might want to get the current page full URL. Here is way you can do that.

/**
* Function for get the full current website page URL
* @return string(full url of current website page)
*/

function fullPageUrl()
{
$pageURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if ($_SERVER["SERVER_PORT"] != "80"){
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

 

Get current page name.

/**
* Function for just getting the current website page name
* @return string
*/

function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

Hope these functions will help you, leave comments if you found anything wrong  or these functions is not working on your page.

Comments (1)

  • Pingback:

Comments are closed.