为什么我重新加载时会设置POST ['submit']?

gia*_*kis 3 php post submit

我的应用程序是一个简单的登录页面 当它失败时,我打印一条错误消息.我的问题是,为什么当我重新加载页面时,邮件再次打印出来?我该如何解决这个问题?代码工作正常,我已经做了另一个php文件执行数据库检查和连接.

<?php 
require_once("include/database.php");       
if(isset($_POST['submit'])) {
    connect_bookstore(); // custom function
    $spassword = sha1($_POST['password']);
    $username = $_POST['username'];
    if ( checkpassword($username,$spassword) ) { //custom function
        header('Location:insert.php');
        exit;
    } else { 
        $message = "Login failed!";         
    }
}   
?>
Run Code Online (Sandbox Code Playgroud)

在html体内.

<?php 
if (isset($message)) {
    echo $message;
}
?>
Run Code Online (Sandbox Code Playgroud)

Kai*_*ing 12

<?php
session_start();

require_once("include/database.php");       
if(isset($_POST['submit'])) {
    connect_bookstore(); // custom function
    $spassword = sha1($_POST['password']);
    $username = $_POST['username'];
    if ( checkpassword($username,$spassword) ) { //custom function
        header('Location:insert.php');
        exit;
    } else { 
        $_SESSION['message'] = "Login failed!";
        header('location: /yourfile.php');
        exit;     
    }
}

if(isset($_SESSION['message']))
{
    echo $_SESSION['message'];
    unset($_SESSION['message']);
}  
?>
Run Code Online (Sandbox Code Playgroud)

从根本上说,是的,发布/重定向/获取...但有时一个简单的解释更好.

我使用会话来存储flash消息,然后像这样显示它们.