php – 当我重新加载时为什么设置POST [‘submit’]?
发布时间:2020-12-13 22:09:03 所属栏目:PHP教程 来源:网络整理
导读:我的应用程序是一个简单的登录页面当它失败时,我打印一条错误消息.我的问题是,为什么当我重新加载页面时,邮件再次打印出来?我该如何解决这个问题? 代码工作正常,我已经做了另一个php文件执行数据库检查连接. ?php require_once("include/database.php"); i
我的应用程序是一个简单的登录页面当它失败时,我打印一条错误消息.我的问题是,为什么当我重新加载页面时,邮件再次打印出来?我该如何解决这个问题?
代码工作正常,我已经做了另一个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消息,然后像这样显示它们. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |