What are potential issues with using Javascript for a back button in PHP applications?

One potential issue with using Javascript for a back button in PHP applications is that it may not work as expected if the user has disabled Javascript in their browser. To solve this issue, you can implement a PHP-based solution that handles the back functionality.

<?php
// Check if the HTTP_REFERER is set and not empty
if(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])){
    // Use the HTTP_REFERER to redirect back to the previous page
    header('Location: ' . $_SERVER['HTTP_REFERER']);
    exit;
} else {
    // If HTTP_REFERER is not set, redirect to a default page
    header('Location: default.php');
    exit;
}
?>