What is the difference between $_SERVER["REQUEST_URI"] and $_SERVER["HTTP_REFERER"] in PHP?
$_SERVER["REQUEST_URI"] contains the URI of the current request, including query parameters, while $_SERVER["HTTP_REFERER"] contains the URL of the previous page that linked to the current page. If you need to get the current page's URL, use $_SERVER["REQUEST_URI"]. If you need to track the referring page, use $_SERVER["HTTP_REFERER"]. It's important to note that $_SERVER["HTTP_REFERER"] may not always be set as it relies on the client sending this information.
$current_page_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$referring_page = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'No referring page';
Keywords
Related Questions
- How can one ensure that the URL variable is properly concatenated and formatted in header(Location: URL) in PHP?
- What are the key considerations for adjusting the width and height of a PHP forum to ensure it aligns with the website layout?
- What potential issue arises in the provided PHP code when trying to create a file list recursively?