0

I am trying to prevent a form being submitted again after page refresh. I looked at some example answers from SO, but it doesn't seem to work. Mainly they mention redirection but when I use this, it takes me to a blank page even if I am trying to redirect to the same page.

Does anybody have an idea on how to fix this? Below is code and near the end is the location code for redirection.

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
    
    if ($_POST["Login"]){
        ...
        $sql = "UPDATE itstusers SET password = ? WHERE username = ?";    
        if($stmt = mysqli_prepare($link, $sql)){
            mysqli_stmt_bind_param($stmt, "ss", $new_password_hash, $reset_param_username);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_close($stmt);
        }
        
        header("location: ./"); 
        exit;
    } 
Barmar
  • 741,623
  • 53
  • 500
  • 612
BruceyBandit
  • 3,978
  • 19
  • 72
  • 144
  • This is redirecting to the action script. You should redirect to the page that displays something. – Barmar Oct 15 '20 at 19:48
  • PHP cannot modify headers if there is any output on the page. If this code is at the bottom of your HTML page, that means there is output on the page, so the redirect won't work and should actually throw an error. – GrumpyCrouton Oct 15 '20 at 19:52

0 Answers0