builds current url, like http://blah.com/some/folders/inside, https://blah.com or create a new one using a path and a query string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function _create_url($uri = null) { | |
$url = "http"; | |
switch (true) { | |
case (isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] === true)): | |
case (isset($_SERVER["HTTP_SCHEME"]) && ($_SERVER["HTTP_SCHEME"] == "https")): | |
case (isset($_SERVER["SERVER_PORT"]) && ($_SERVER["SERVER_PORT"] == 443)): | |
$url .= "s"; | |
break; | |
} | |
$url .= "://"; | |
$url .= $_SERVER["SERVER_NAME"]; | |
if ($_SERVER["SERVER_PORT"] != 80) { | |
$url .= ":" . $_SERVER["SERVER_PORT"]; | |
} | |
$uriDirname = dirname($_SERVER["REQUEST_URI"]); | |
if ("/" != $uriDirname) { | |
$url .= $uriDirname; | |
} | |
if (!empty($uri)) { | |
$url .= $uri; | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment