double submit problem
Results 1 to 3 of 3

Thread: double submit problem

  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    10

    Post 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..

  2. #2
    Junior Member
    Join Date
    Dec 2003
    Posts
    24
    If I understand your problem, this might help:

    PHP Code:
    // check to see if any post data was submitted
    if (count($_POST) &gt)
    {
        
    // 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();
        }
        else
        {
            
    // 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
            //
            //
        
    }


  3. #3
    Junior Member
    Join Date
    Sep 2005
    Posts
    10
    Thanks it did help..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •