Get Current Page URL
function getUrl() {
$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
$url .= $_SERVER["REQUEST_URI"];
return $url;
}
Thanks, really useful. I was looking for this long time. :)
Don’t suppress errors please. Especially not on an educational site like this one!
Thanks, very handy.
I think a “not equal to” as opposed to a “not identical to” should have the desired effect ($_SERVER["SERVER_PORT"] != 80) .
Yah! It worked! I liked It… Thanks CSS-TRICKS
But there should be echo getUrl();
Why do you need to show the port number? I removed the line;
$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? “:”.$_SERVER["SERVER_PORT"] : “”;