Skip to content
Advertisement

php – prevent back button

This is a part of my payment.php code. $f=1 when the values got stored in database correctly.

JavaScript

Now we all know window.location.replace() replaces the current page, removing the previous one from the back button history.

But the back button is working.

I do not want the user to press the back button and enter the payment.php again. So, what should i do with it?

Same goes for my login.php page, it redirects to home.php but again one can press back button and get to login.php.

How should i prevent it?

I even tried this:

JavaScript

But even it isn’t working.

Please help

Advertisement

Answer

I think you can work with the Unload Event and the History Function.

JavaScript

Add this before your Body Tag gets closed.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement