Is storing the user's previous page in a session a reliable method for creating a "Back Button" in PHP?

Storing the user's previous page in a session can be a reliable method for creating a "Back Button" in PHP. By saving the URL of the current page in a session variable, you can easily redirect the user back to that page when needed. This approach can be useful when navigating through multiple pages and wanting to provide a convenient way for users to return to the previous page.

session_start();

// Save the current page URL in a session variable
$_SESSION['previous_page'] = $_SERVER['REQUEST_URI'];

// Use this code to redirect the user back to the previous page
if(isset($_SESSION['previous_page'])){
    header('Location: ' . $_SESSION['previous_page']);
    exit();
} else {
    // Redirect to a default page if no previous page is stored
    header('Location: default_page.php');
    exit();
}