Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
<?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
You can’t perform that action at this time.