This is a PHP function used to retrieve the URL of the current request. It constructs the URL based on the current request's protocol, host, and path, and then returns that URL.
The code logic within the function is as follows:
First, by making a judgment$_SERVER['HTTPS']Determine whether the value is 'on' to ascertain if the current request uses the HTTPS protocol. If so, set the protocol to HTTPS.'https'; otherwise, set to'http'。
Next, retrieve.$_SERVER['HTTP_HOST']The value represents the hostname of the current request.
Then, retrieve.$_SERVER['REQUEST_URI']The value represents the path of the current request.
Finally, combine the protocol, host, and path to form a complete URL and return it.
PHP code
public function getUrl() {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$path = $_SERVER['REQUEST_URI'];
$url = $protocol . '://' . $host . $path;
return $url;
}