Search code examples
phphttp-redirectback

PHP - Prevent user from using back


I have had a look around, but the closest I found was for asp.net. I would like to prevent the user from pressing the back button in the browser, or if possible link him to a different page if he does press the back button.

Page 1: Register Page 2: Register Complete When the user presses back it should redirect him to the homepage (home.html).

All help is welcome!


Solution

  • You can't prevent him from using back. Period. Even when you open a popup and hiding the navigation buttons it can be circumvented.

    What you could do, when the user is registered, set a cookie or store something in $_SESSION, and if the user is registered ($_SESSION['justRegistred'] = true), you can check that if that value exists when on Page 1. If the value exists and is true, do a header_location('.../home.php')