Php 为什么在重新加载时设置POST[';submit';]?
我的应用程序是一个简单的登录页面。当它失败时,我打印一条错误消息。我的问题是,为什么我重新加载页面时会再次打印消息?我怎样才能解决这个问题? 代码运行良好,我制作了另一个php文件,执行数据库检查和连接Php 为什么在重新加载时设置POST[';submit';]?,php,post,submit,Php,Post,Submit,我的应用程序是一个简单的登录页面。当它失败时,我打印一条错误消息。我的问题是,为什么我重新加载页面时会再次打印消息?我怎样才能解决这个问题? 代码运行良好,我制作了另一个php文件,执行数据库检查和连接 <?php require_once("include/database.php"); if(isset($_POST['submit'])) { connect_bookstore(); // custom function $spassword = sh
<?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!";
}
}
?>
在html主体内部
<?php
if (isset($message)) {
echo $message;
}
?>
这是因为刷新时正在重新发送相同的POST数据,如果执行GET请求,您将在URL中注意到您传递的参数在那里,因此,如果刷新,这些参数将再次发送。POST也是一样。重新加载页面时,浏览器将发送与原始页面相同的请求
您需要一个密码。
基本上,是的,发布/重定向/获取。。。但有时一个简单的解释更好
我使用会话来存储flash消息,然后像这样显示它们。可能的重复
<?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']);
}
?>