get_current_url

(PHP >= 4.10, PHP 5, PHP 7)

get_current_urlParse a URL and return its components

Description

mixed get_current_url ( void )

This function determines the current URL used to access the main PHP script that is being called via a web server.

Parameters

This function has no parameters.

Return Values

Returns the current URL, if the main PHP script is being called via a web server which uses a CGI compatible interface ; otherwise, FALSE.

Changelog

Version Description gist URL
1.0 Initial version.

Examples

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"

Notes

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.

See Also

  • $_SERVER - Server and execution environment information

To Top