PHP function to get current web page full URL

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.

[php]
/**
* 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;
}
[/php]

 

Get current page name.

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

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

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

2 thoughts on “PHP function to get current web page full URL”

  1. Pingback: zftre yuli ghut

Comments are closed.