Saturday, August 7, 2010

get the current page name without full domain

Use:

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

echo "This page name is ".curPageName();
?>//

This will give you just page.html etc..

Current Page Name in PHP

Paste this code anywhere on your page or include:

//function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
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;
}
?>//

Then you can output the current page name using:

// echo curPageURL();
?>//

Simple and easy, and a great little piece of code!

note**** remove the "//"