...

View Full Version : Refresh A Page If Back Button Is Hit



tomyknoker
09-02-2007, 02:11 AM
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?

Mwnciau
09-02-2007, 02:27 AM
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.

tomyknoker
09-02-2007, 02:31 AM
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?

Mwnciau
09-02-2007, 02:54 AM
At the top of insert.php put this:


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:



$_SESSION['submitted'] = true;

tomyknoker
09-02-2007, 03:01 AM
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?


// 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?


<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" />

tomyknoker
09-02-2007, 03:16 AM
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?

Mwnciau
09-02-2007, 03:38 AM
Just put


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum