Forum Moderators: coopster
I thought of adding a random code that changes as soon as the form submission has been received, but it does not work. Probably it has to do with the way and order in which php processes a page but I am not sure.
This is what I tried:
$_SESSION['randomnumber']=makerandompassword();
echo '<form name="form1" method="POST" action="">';
echo '<input type="submit" value="submit">';
echo '<input name="rand" type="hidden" value="'.$_SESSION['randomnumber'].'">';
echo '</form>';
if (($_POST['rand'])==$_SESSION['randomnumber']) {
echo 'new submit received';
}
else
{ echo "refreshed";$_SESSION['randomnumber']=makerandompassword(); exit;}
Am I on the right track, or does anyone know another way?
I tried the following but when I echo $_SESSION['rand'] on the process page it remains empty while on the form page it does have a value.
FORM PAGE test.php:
<?php
session_start();
include 'functions.php';
$SESSION['rand']=makerandompassword();
echo '<form name="form1" method="POST" action="process.php">';
echo '<input type="submit" value="submit">';
echo '<input name="rand" type="hidden" value="'.$SESSION['rand'].'">';
echo '</form>';
?> PROCESS PAGE process.php
<?php
session_start();
//check form page
if (($_POST['rand'])==($_SESSION['rand'])) {
echo 'new';
//do other form processing here
header("Location: thanks.php");}
else { echo 'error resubmit';
echo $_POST['rand']; echo '-'.$_SESSION['rand'];
}
?> THANKS PAGE thanks.php
<?php
session_start();
echo 'thanks';
include 'test.php';
?>