Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created April 23, 2014 20:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nebiros/11231362 to your computer and use it in GitHub Desktop.
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