Skip to content

Instantly share code, notes, and snippets.

@cbejensen
Last active February 15, 2018 16:16
Show Gist options
  • Save cbejensen/58fdbcbe98022fddba52a88aece44a5c to your computer and use it in GitHub Desktop.
Save cbejensen/58fdbcbe98022fddba52a88aece44a5c to your computer and use it in GitHub Desktop.
Get the full URL in PHP
<?php
function get_full_url() {
$url = ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) ? 'https' : 'http';
$url .= '://' . $_SERVER['SERVER_NAME'];
$url .= in_array( $_SERVER['SERVER_PORT'], array( '80', '443' ) ) ? '' : ":" . $_SERVER['SERVER_PORT'];
$url .= substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1);
return $url;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment