Skip to content

Instantly share code, notes, and snippets.

@kenee
Created June 26, 2013 08:29
Show Gist options
  • Save kenee/5865740 to your computer and use it in GitHub Desktop.
Save kenee/5865740 to your computer and use it in GitHub Desktop.
php get self
function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = $this->strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
: (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.dirname($_SERVER['REQUEST_URI'])."/";
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment