What is the function in PHP to retrieve the URL of the current page?
To retrieve the URL of the current page in PHP, you can use the $_SERVER['REQUEST_URI'] superglobal variable. This variable contains the URI of the current request. By concatenating it with the 'http://' or 'https://' and the $_SERVER['HTTP_HOST'] variable, you can obtain the full URL of the current page.
$currentURL = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $currentURL;
Keywords
Related Questions
- How does JSON compare to YAML in terms of readability and ease of use for saving object data across different languages?
- What are some potential pitfalls to consider when automatically converting text to gif or jpg banners using PHP?
- What are the potential pitfalls of using prepared statements in PHP PDO for database queries?