Are there alternative methods to track the previous page in PHP besides using $HTTP_REFERER?

Using $HTTP_REFERER to track the previous page in PHP is not always reliable as it can be easily manipulated or disabled by the user's browser settings. An alternative method to track the previous page is to use sessions to store the previous URL when a user navigates to a new page. This way, you can access the previous page URL regardless of the user's browser settings.

// Start the session
session_start();

// Store the current page URL in a session variable
$_SESSION['previous_page'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';

// Access the previous page URL
$previous_page = $_SESSION['previous_page'];

// Output the previous page URL
echo $previous_page;