Is there a way in PHP to retrieve the requesting URL of the requesting URL (two levels back) for page navigation purposes?

When navigating between pages on a website, it can be useful to retrieve the URL of the previous page (two levels back) for various purposes. In PHP, you can achieve this by using the `$_SERVER['HTTP_REFERER']` variable to get the URL of the immediate referring page and then parsing it to extract the URL two levels back.

// Retrieve the URL of the immediate referring page
$referer = $_SERVER['HTTP_REFERER'];

// Parse the URL to extract the URL two levels back
$urlParts = parse_url($referer);
$previousUrl = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'];
echo $previousUrl;