Issue with resubmitting form data

I am a newbie trying to develop a login bar. The problem is that

I am unable to stop re-submitting the form data when the browser's back and forth button is clicked. Tried looking for it on google but no effective solution found.

Please enlighten me on this.

+2


source to share


1 answer


You probably want to implement the Post-Redirect-Get method .

Since you made a post and you didn't redirect, the POST data may be sent again due to browser behavior. You have to redirect after POST to stop this.

The diagram below shows the PRG flow:

alt text http://upload.wikimedia.org/wikipedia/en/3/3c/PostRedirectGet_DoubleSubmitSolution.png



To do this, on your publish page, instead of displaying results, you redirect the user to a different results page.

eg.

function redirect($url){
  header('Location: '.$url);
  exit;
}

if(isset($_POST['submit'])){
  $ok = checkLogin($username,$password);
  if($ok){
    redirect('thank-you.php');
  }else{
    redirect('login.php?error');
  }
}

      

+3


source







All Articles