Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Refresh A Page If Back Button Is Hit

    Hi all... I have a php page which is a sign up page, once signup is finished the user is redirected to a new page. Sometimes (and it's rare) the user hit's the back button and then re-submits the form etc... I mean like I said it's rare but still bothers me, so on the last page I kill all the sessions... Which only works if the user hits the back button but the page is refreshed... So basically I want to know if it's possible that when the back button is hit to refresh a php page? can it be done in php? Or do I need to move this to the JavaScript forum?

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You could store in the session a variable when they submit the form, and before you process the form after submission check if the variable has already been set, if it has then don't process the form.

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    But if they re-submit the form it adds a 'NEW' user ID in the database, so would that still work? From my signup.php, it goes to insert.php and once all the data is inserted then goes to final.php... Can you possibly explain what I need to put where if that's going to work?

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    At the top of insert.php put this:

    PHP Code:
    session_start();
    if(
    $_SESSION['submitted'] == true){
    header('Location: final.php');
    die();

    and after you have processed the form successfully in insert.php put this in:

    PHP Code:
    $_SESSION['submitted'] = true

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks heaps you're a legend! Ok I have been playing around from Google searches... I added the following at the end of insert.php, which I'm guessing I should now remove yes?

    PHP Code:
    // Kill all session variables
            
    session_destroy(); 
    Also on signup.php which is the sign up form I was reading would be good to add some META's should I keep them or is it pointless?

    Code:
    <meta http-equiv="expires" content="Sun, Dec 31 1970 12:00:00 GMT" />
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache" />

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey Mwnciau... Well I think that's worked, only issue I'm having is that if they hit back... It takes them to the last page of the form... With the fields still in there... And say they hit submit, it takes them to lastpage.php still saying 'you have signed up etc'... The good thing is they aren't getting entered into the database again... And the other issue is I can't get rid of the sign up form now on the last page, unless I completely reset the browsers cache etc is there any way around that?

  • #7
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Just put

    PHP Code:
    session_start();
    if(
    $_SESSION['submitted'] == true){
    header('Location: final.php');
    die();

    on each page you don't want them to go to after they have signed up.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •