我的应用程序是一个简单的登录页面。当失败时,我会打印一条错误消息。我的问题是,为什么当我重新加载页面时,消息会再次打印?我该如何解决这个问题?
代码工作正常,我制作了另一个执行数据库检查和连接的 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!";
}
}
?>
在 html 主体内部。
<?php
if (isset($message)) {
echo $message;
}
?>
<?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']);
}
?>
从根本上来说,是的,发布/重定向/获取...但有时简单的解释会更好。
我使用会话来存储 Flash 消息,然后像这样显示它们。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)