Instructions: Paste this script in your PHP document where you wish the url of the page to occurÂÂ
<?phpÂÂ
function selfURL() {ÂÂ
   $s = empty($_SERVER["HTTPS"]) ? ” : ($_SERVER["HTTPS"] == “on”) ? “s” : “”;ÂÂ
   $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), “/”).$s;ÂÂ
   $port = ($_SERVER["SERVER_PORT"] == “80″) ? “” : (“:”.$_SERVER["SERVER_PORT"]);ÂÂ
return $protocol.“://”.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];ÂÂ
}ÂÂ
function strleft($s1, $s2) {ÂÂ
  return substr($s1, 0, strpos($s1, $s2));ÂÂ
}ÂÂ
?>

Discussion
No comments for “PHP code to get the url of a webpage”