Last active
December 10, 2015 22:18
-
-
Save SleeplessByte/4501468 to your computer and use it in GitHub Desktop.
Gets the current displayed url for a page. key <> value pairs can be stripped from the url by key.
This file contains hidden or 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 | |
/** | |
* Gets the current displayed url | |
* @strip array of key names to be stripped from the url | |
* @returns the url | |
*/ | |
protected function get_current_url( $strip = NULL ) { | |
$url = isset( $_SERVER["HTTPS"] ) && $_SERVER['HTTPS'] == "on" ? 'https://' : 'http://'; | |
$url .= ( strlen( $_SERVER["SERVER_NAME"] ) ? $_SERVER["SERVER_NAME"] : $_SERVER['HTTP_HOST']); | |
$url .= ( !in_array( strval( $_SERVER["SERVER_PORT"] ), array( "80", "443" ) ) ) ? $_SERVER["SERVER_PORT"] : ''; | |
if (!is_null($strip)) : | |
$url .= preg_replace( "/[&\?](".implode("|", $strip).")=?[^&]*/", "", $_SERVER["REQUEST_URI"] ); | |
else : | |
$url .= $_SERVER["REQUEST_URI"]; | |
endif; | |
return $url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment