Created
March 11, 2011 17:26
-
-
Save peteboere/866231 to your computer and use it in GitHub Desktop.
function to get the current URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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