Created
October 13, 2012 02:44
-
-
Save plasticbrain/3883001 to your computer and use it in GitHub Desktop.
PHP: Get the full URL of the current page
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
| function current_page($params=NULL, $no_trailing_slash=TRUE) { | |
| // http(s)://domain.com | |
| $url = @$_SERVER['HTTPS'] == 'on' ? 'https://'. $_SERVER['SERVER_NAME'] : 'http://'.$_SERVER['SERVER_NAME']; | |
| // add the port number, if there is one | |
| if( @$_SERVER['SERVER_PORT'] != "80" && @$_SERVER['SERVER_PORT'] != "443" ) $url .= ':'. @$_SERVER['SERVER_PORT']; | |
| // Append the query string | |
| $url .= $_SERVER['REQUEST_URI']; | |
| // [optionally] remove the trailing slash if there is one | |
| if( $no_trailing_slash ) $url = rtrim($url, '/'); | |
| // Add any additional parameters that may have been included | |
| if( $params ) $url .= $params; | |
| return $url; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment