Skip to content

Instantly share code, notes, and snippets.

@pwenzel
Last active June 30, 2018 06:26
Show Gist options
  • Save pwenzel/4567675 to your computer and use it in GitHub Desktop.
Save pwenzel/4567675 to your computer and use it in GitHub Desktop.
Get Current URL with PHP. Inspired by CodeIgniter. Tested with Wordpress with and without fancy permalinks.
<?php
function get_the_current_url() {
$protocol = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url = $protocol . "://" . $_SERVER['HTTP_HOST'];
$complete_url = $base_url . $_SERVER["REQUEST_URI"];
return $complete_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment