URLs

Get the current URL

$url =
    'http' . (isset($_SERVER['HTTPS']) ? 's' : '' ) .
    '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";

Get the parts of a URL

$url = 'http://username:password@hostname:9090/path?arg=value#anchor';

echo parse_url($url, PHP_URL_SCHEME); // Returns "http"
echo parse_url($url, PHP_URL_USER);   // Returns "username"
echo parse_url($url, PHP_URL_PASS); // Returns "password"
echo parse_url($url, PHP_URL_HOST); // Returns "hostname"
echo parse_url($url, PHP_URL_PORT); // Returns ""
echo parse_url($url, PHP_URL_PATH); // Returns "/path"
echo parse_url($url, PHP_URL_QUERY); // Returns "arg=value"
echo parse_url($url, PHP_URL_FRAGMENT); // Returns "anchor"

// Get all the URL parts in an array.
$url_parts = parse_url($url);