May 30th, 2006, 12:40 PM
double submit problem
hi i was developing a php script and i came across this double submit problem..
When a user reloads my results page the browser fires of a warning that postdata is being sent again..i deliberately put the sql code of inserting the postdata in the db on the results page to avoid the use of Redirect..
one way i tried to solve the problem was declaring a session variable $_SESSION['posted']=0 before inserting the message and after the message has been inserted into the db $_SESSION['posted'] was set to 1 which can be then checked in case of a reload.$_SESSION['posted'] is set to 0 again when the user visits the submit page. although this helped with the reload problem but not with the associated browser warnings.and anyways it doesnt help when a user uses the back and forward buttons..
does anybody know a good solution to this problem??thanks in advance..
June 2nd, 2006, 03:57 PM
If I understand your problem, this might help:
// check to see if any post data was submitted
if (count($_POST) > 0 )
// see if the post is the same as the one we just received
if ($_SESSION['post_hash'] == md5(serialize($_POST)))
// if it is kill it by reseting the $_POST array
$_POST = array();
// if not, set 'post_hash' to a string that represents the posted data
$_SESSION['post_hash'] = md5(serialize($_POST));
// add your normal validation and insert code here
June 4th, 2006, 01:54 PM