3

I heard that this is bad idea but I'll try to explain what I want to achieve:

On my site a user fills some information and then goes to another service which handles user payment. So after the user pays using credit card he got redirected to special $successUrl again to my site where he sees successful payment message. My boss wants that after payment if the user clicks back button (being on success page) instead of going to payment service again he have to be redirected to main page.

How to achieve that? I can't thought of a good solution. Only something like catch back button event on this page and redirect to index page

Victor
  • 5,073
  • 15
  • 68
  • 120
  • 3
    Use location.replace("mainpage.php?paymentdetails") and have mainpage.php call the payment – mplungjan Feb 19 '14 at 16:47
  • https://github.com/browserstate/history.js/ this only works on html5 browsers. It allows you to manipulate user browser history – Fabio Antunes Feb 19 '14 at 16:49
  • put a header refresh based on a get variable planted in someCookie on successful completion of payment process? – Philip Bevan Feb 19 '14 at 16:50
  • mplungjan, Honestly I didn't understand your answer but as it's voted up I think you should make an answer with some more details. My php scheme is: index.php -> step1.php -> step2.php -> post request with success url to other service -> returning to success.php after payment – Victor Feb 19 '14 at 16:55
  • 1
    possible duplicate of [Is there a way to catch the back button event in javascript?](http://stackoverflow.com/questions/136937/is-there-a-way-to-catch-the-back-button-event-in-javascript) – Fabio Antunes Feb 19 '14 at 17:01

2 Answers2

0

I think the only way to to it is with javaScript

You can bind to "navigate" event.

$(window).on("navigate", function (event, data) {
  var direction = data.state.direction;
  if (direction == 'back') {
    window.location.href='http://google.com';
    event.preventDefault();
  }
});
0

You can make the success page, let's call it SuccessRedirect, redirect the browser (using javascript or HTML meta header, you can't use a HTTP header) to another page, SuccessActual, that displays the success message.

On the first visit to SuccessRedirect page set a cookie, so that if someone visits it the second time (i.e. after clicking the Back button) and the cookie is already set, instead of redirecting to SuccessActual it redirects to the homepage.

The cookie name should include some kind of payment transaction id, so that you display the success page for every payment transaction.

It's a bit hacky and it won't work if someone quickly clicks 'Back' multiple, but hey, it might work well enough.

Michał Tatarynowicz
  • 1,294
  • 2
  • 15
  • 33