(PHP >= 4.10, PHP 5, PHP 7)
get_current_url — Parse a URL and return its components
This function determines the current URL used to access the main PHP script that is being called via a web server.
This function has no parameters.
Returns the current URL, if the main PHP script is being called via a web server which uses a CGI compatible interface ; otherwise,
FALSE
.
Version | Description | gist URL |
---|---|---|
1.0 | Initial version. |
Example #1 A get_current_url() example
<?php
var_dump(get_current_url());
?>
If called from the command line, the above example will output:
bool(false)
If called from a web page via the URL "https://localhost:443/phpinfo.php?query#fragment", the above example will output:
string(35) "https://localhost/phpinfo.php?query"
Note:
This function may omit the port number as it is actually used in the called URL if it is the default port number for the used protocol.