Skip to content

Instantly share code, notes, and snippets.

@peteboere
Created March 11, 2011 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteboere/866231 to your computer and use it in GitHub Desktop.
Save peteboere/866231 to your computer and use it in GitHub Desktop.
function to get the current URL
<?php
function get_current_url ( $include_request_uri = true ) {
$https = isset( $_SERVER[ "HTTPS" ] ) && strtolower( $_SERVER[ "HTTPS" ] ) === "on";
$protocol = 'http' . ( $https ? 's' : '' ) . '://';
$host = $_SERVER[ "SERVER_NAME" ];
$port = $_SERVER[ "SERVER_PORT" ];
$request = $include_request_uri ? get_request_uri() : '';
return $protocol . $host . ( $port != 80 ? ":$port" : '' ) . $request;
}
function get_request_uri () {
$request_uri_supported = isset( $_SERVER[ "REQUEST_URI" ] ); // IIS
$request = $request_uri_supported ? $_SERVER[ "REQUEST_URI" ] : $_SERVER[ "PHP_SELF" ];
$request = htmlspecialchars( $request ); // XSS
if ( !$request_uri_supported and count( $_GET ) ) {
$request .= '?' . http_build_query( $_GET );
}
return $request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment