Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Last active August 26, 2017 12:46
Show Gist options
  • Save jasondmoss/7344284 to your computer and use it in GitHub Desktop.
Save jasondmoss/7344284 to your computer and use it in GitHub Desktop.
Get Current URL
<?php
/**
* Get current URL
*
* @param boolean $echo (Optional) Whether to echo or return value.
*
* @return string
* @access public
*/
function getCurrentUrl($echo = false)
{
$currentUrl = 'http'. ((isset($_SERVER['HTTPS'])) ? 's' : '') .'://'. $_SERVER['SERVER_NAME'];
$currentUrl .= ('80' != $_SERVER['SERVER_PORT'])
? $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']
: $_SERVER['REQUEST_URI'];
return ($echo) ? _e($currentUrl) : $currentUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment