PHP function to get current web page full URL

Nov 06, 2013, by admin

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, to get more updates like the page Bugtreat Technologies and like the page Cs Cart Templates for instant updates of our templates

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.