Saturday, August 7, 2010

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 "//"

1 comment:

  1. Hi,It takes a real web developer to create easy sites that are both attractive and easy. Simpleness in Web Design Cochin should not by replacements with ugliness.Thanks....

    ReplyDelete