How can the PHP code replace the JavaScript function history.back() for creating a "Back Button"?

To replace the JavaScript function history.back() with PHP, we can use the header() function to redirect the user to the previous page. This can be achieved by using the $_SERVER['HTTP_REFERER'] variable, which contains the URL of the previous page visited by the user.

<?php
if(isset($_SERVER['HTTP_REFERER'])) {
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    header('Location: /'); // Redirect to home page if no previous page is available
}
exit;
?>