Tuesday, September 8, 2009

Using PHP code to get the current page URL?

the following function will get the current page URL using php code:

<?php

function currentPageURL() {

$curpageURL = ‘http’;


if ($_SERVER["HTTPS"] == “on”) {$curpageURL.= “s”;}

$curpageURL.= “://”;

if ($_SERVER["SERVER_PORT"] != “80″) {

$curpageURL.= $_SERVER["SERVER_NAME"].”:”.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];


} else {

$curpageURL.= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

}

return $curpageURL;

}


echo currentPageURL();

?>

No comments:

Post a Comment