PHP Survey Form and Disabling Back button in web browser

Hi experts (and geniuses)!

I have a PHP survey form. People may fill out the form on the "page1.php" and preview the input by clicking "Submit button at bottom (in other words, once "Submit" button is clicked, preview page is displayed). The preview page has two buttons: 1. Proceed (to finally submit) and 2. "Edit" (to go back to "Page1.php" to make changes).

My question is: Is there a way to make it impossible to go back to the "Page1.php" once "Proceed" button is clicked?
I do remember that when I tried to go back to the previous page in some web sites like Paypal or Amazon.com", I could not go back to the previous page. Instead a message showed on light gray screen, saying some messages (whose words I could not remember).

You might ask why I need to do that. The answer is: Some people submitted more thahn once, going back and forth between "Page1.php" and preview.php. Currently, anyone may submit as many as he/she wants: It could be a major problem for me.

Thanks a lot!



dutaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ljubiccicaConnect With a Mentor Commented:
*****************page 1**************************

<?php
session_start();
?>

<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="page2.php" name="myform">
First Name <input type="text" size="12" maxlength="12" name="Fname"><br />
Last Name <input type="text" size="12" maxlength="36" name="Lname"><br /><br>

<?php
if(!isset($_SESSION['proceeded'])){
?>
<input type="submit" value="preview" name="submit">    <input type="button" value="reset" onclick="javascript: document.myform.reset();">
<?php
}else{
echo "You have already filled this form...";
}
 ?>
</form>
</html>



**************************page 2*************************

<?php
session_start();

if(isset($_SESSION['proceeded'])){
header("Location:page1.php");
}
?>

<html>
<head>
<title>Personal INFO</title>
</head>
<body>
<form method="post" action="page3.php">
First Name <input type="text" size="12" maxlength="12" name="Fname" value="<?php echo $_POST['Fname']?>"><br />
Last Name <input type="text" size="12" maxlength="36" name="Lname" value="<?php echo $_POST['Lname']?>"><br />

<input type="submit" value="proceed" name="submit"><br />
</form>
</html>

******************************page 3***************************

<?php
session_start();
//you can have it pass these values to some mysql database ot something and let the user go manually to some other page
if(isset($_SESSION['proceeded'])){
header("Location:page1.php");
}
?>
<html>
<head>
<title>Personal INFO</title>
</head>
<body>
First name:<?php echo $_POST['Fname']?><br />
Last name:<?php echo $_POST['Lname']?><br /><br />

<a href="page1.php">first page</a>

<?php
$_SESSION['proceeded'] = true;
?>

</html>


************one more thing************
if you want to go directly to page 1 after you send data, you do it like this on page 3


<?php
session_start();
//you can have it pass these values to some mysql database ot something and let the user go manually to some
/// pass mysql etc....
/// pass mysql etc....


header("Location:page1.php");
?>


************ the end****************

Hope it helps....

Ljubiccica
0
 
ljubiccicaCommented:
The easiest thing to do is with sessions

On the second page you make a session like $_SESSION['proceded']=true;

And than on the first page, before you do anything else you do this

if(isset($_SESSION['proceded']){
header("Location:somePageYouWant.php");
}

You know how to strat with sessions and everything?

Ljubiccica
0
 
ljubiccicaCommented:
ha
this will be better:

if(isset($_SESSION['proceded'])){
header("Location:somePageYouWant.php");
}

;-)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
dutaAuthor Commented:
TO: ljubiccica :

Thank very much for your kind, prompt response.

I tried your scripts, but it did not work.

Can you create and post here a very simple pages so that I may test it?
For your info, my pages are as follows:
Page 1 has "preview" button and reset button.
preview page has  "proceed" button and "edit" button.
What I would like to do is: Once a person finished previewing the page and click "proceed" button, he may be able to go one page back to page1 so that he may not be able to submit again and again and again.
0
 
ljubiccicaCommented:
Ok...

will do it in a moment...
0
 
dutaAuthor Commented:
TO: ljubiccica

Thank you so much for your very kind help.
I will test yur script and come back to you as soon as possible.

I will writing this message upon checking your post.

Thanks again!

duta
0
 
dutaAuthor Commented:
TO: ljubiccica :

Thank you very much for your kind script.

Yur scripts worked just fine. But there is a problem: I could re-submit the form after closing and re-opening a web browser. I just wonder whether there is a solution to this.

Thanks!

duta
0
 
ljubiccicaCommented:
Do you use any mysql database?

Look, there is no 100% way you can do it...

You can make a cookie with php -> but a smart user can always delete cookies and he may re-submit the form again.

The other way is you make a field in your form like e-mail address, write it into database and you check this address before the user submits his form.

The third way is to block IP, but i wouldn't do that because sometimes more people (maybe 1000 or more) use the same IP address...

So if you combine first two you will make a good work... But even then you will have some "web experts" that will be able to go around it...

0
 
dutaAuthor Commented:
TO: ljubiccica :

Thank you so much for your very kind, prompt response.

I will try the others things you recommended for me and come back to you asap.

Thanks again!

duta
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.