Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created May 24, 2013 00:49
  • 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 jaredatch/5640597 to your computer and use it in GitHub Desktop.
<?php
/**
* Grabs the full URL of the current page and returns it
*
* @since 1.0.0
* @link http://stackoverflow.com/questions/6768793/php-get-the-full-url
* @return string
*/
function ja_full_url(){
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$sp = strtolower($_SERVER["SERVER_PROTOCOL"]);
$protocol = substr($sp, 0, strpos($sp, "/")) . $s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
$full_url = esc_url( $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'] );
return $full_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment