-1

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!

CustomX
  • 9,948
  • 30
  • 85
  • 115
  • 5
    Websites that try to mess around with the back button are a pain in the arse. Please don't do this! – Oliver Charlesworth Jan 20 '12 at 09:52
  • What technique did the `ASP.NET` solution use? Are you unable to port it to PHP, if so, why? – zrvan Jan 20 '12 at 09:52
  • I saw this post: http://stackoverflow.com/questions/1076988/how-can-i-prevent-the-user-from-navigating-back-to-a-previous-page – CustomX Jan 20 '12 at 09:54
  • I know it might be a bitch, but I'm sure it must be solvable? – CustomX Jan 20 '12 at 09:54
  • the only question left is what about already registered users. are they allowed to see registration page at all? if so, the whole mess become useless. if not - the solution become quite useless. Calling yourself "a bitch" is not an excuse for keeping with wrong question. – Your Common Sense Jan 20 '12 at 10:10
  • Rather than disabling the back button you should be writing your system to cope with it gracefully. – vascowhite Jan 20 '12 at 10:15
  • Why would "I" as a user press back button to go the home page when I had come from the registration page? – andho Jan 20 '12 at 10:16
  • If you are worried about the form being posted again, it is possible to prevent this. – andho Jan 20 '12 at 10:17
  • I thank you all for you experiences, but I'm not bothered what you think about my work method. I asked a question and received help, I don't see why people need to dislike the question. – CustomX Jan 20 '12 at 10:18
  • @col shrapnel, I said the question was a bitch. I have it all sorted out now. – CustomX Jan 20 '12 at 10:18
  • @tom people 'dislike' the question because that is how Stackoverflow works. http://stackoverflow.com/faq – vascowhite Jan 20 '12 at 10:22
  • hehe, you're wrong :) You don't have it sorted out but actually you just entering the mess :) – Your Common Sense Jan 20 '12 at 10:48
  • Might I suggest a different approach all together. It's not exactly according to the specifications, but why not use AJAX to load the registration components in the correct order? That would avoid accidental back-button clicking and the general annoyance expressed here concerning the issue. – zrvan Jan 20 '12 at 14:13
  • Or, perhaps, consider doing it through JavaScript, not fool-proof, but hey! http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript – zrvan Jan 20 '12 at 14:19
  • zrvan, thanks for your tips. But I decided to use a session. This looks like a good way to solve it according to me. – CustomX Jan 21 '12 at 12:22

4 Answers4

6

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')

Anemoia
  • 7,928
  • 7
  • 46
  • 71
  • I think this might be the best solution. So techincally the user goes from page 1 to page 2 and receives a session on page 2. If he presses back, he will return to page 1 but because the session he's received he will be linked to a different page? Will the user see any of this? – CustomX Jan 20 '12 at 10:00
1

It is discouraged for usability reasons to do so, but technically it's possible with a session that keeps track if the user has completed registration.

If the user has completed registration and opens the Register Page again she is being redirected.

From the users point of view it looks like that if back is not working.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • I think a session will be my best option. – CustomX Jan 20 '12 at 10:02
  • 1
    It depends on what you want to achieve. Session handling can have unexpected side-effects for your users. To prevent side-effects increase your site's usability instead. E.g. Get redirect after Post submit. Also you can make the `Register Complete` page have the same URL as the `Register Page` which normally works much better and is more transparent to the user. – hakre Jan 20 '12 at 10:05
  • They are redirected from page 1 to page 2 and there they need to click any menu item. I just want to prevent them from going back to the register form using back, so sessions sound good. – CustomX Jan 20 '12 at 10:12
1

You could also check on


$_SERVER['HTTP_REFERER'];

If refering page is registration complete then show homepage.

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
1

When the user first arrives on the view page, you can create a variable stored in the current session, if it is not already defined. If it is already created, you just check to see if the user completed the registration process, like this:

if( isset( $_SESSION[ "userRegistered" ] ) && $_SESSION[ "userRegistered" ])
    header("Location: index.php"); // go to the home page if the registration is already done
else
    $_SESSION["userRegistered"] = false;

Then, after the registration process, set that same variable to true;

Now, if the user presses back, the registration page will check if the process is completed, and if so, it will redirect the user.

Hope this helps. Have a great day.

Romi Halasz
  • 1,949
  • 1
  • 13
  • 23
  • thanks, this is like Snake said, but with code. So this goes in page 1 and on page 2 I would set assign a session, correct? – CustomX Jan 20 '12 at 10:02