?
Solved

PHP Survey Form and Disabling Back button in web browser

Posted on 2006-06-13
11
Medium Priority
?
282 Views
Last Modified: 2008-02-20
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!



0
Comment
Question by:duta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 7

Expert Comment

by:ljubiccica
ID: 16898193
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
 
LVL 7

Expert Comment

by:ljubiccica
ID: 16898214
ha
this will be better:

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

;-)
0
 

Author Comment

by:duta
ID: 16898303
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:ljubiccica
ID: 16900239
Ok...

will do it in a moment...
0
 
LVL 7

Accepted Solution

by:
ljubiccica earned 2000 total points
ID: 16900378
*****************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
 

Author Comment

by:duta
ID: 16902171
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
 

Author Comment

by:duta
ID: 16902399
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
 
LVL 7

Expert Comment

by:ljubiccica
ID: 16902572
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
 

Author Comment

by:duta
ID: 16902617
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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question