我目前在我的项目中有这个代码:
require_once('mysql.inc.php');
session_start();
if (!isset($_SESSION['username']) && !isset($_SESSION['uid']))
{
login_sequence();
}
else
{
login_check($_SESSION['username'], $_SESSION['uid']);
}
function login_sequence()
{
echo '<p>' . $pretext . '</p><form method="post" action="" /><label for="password">Password: </label><input type="password" name="password" id="password" /><input type="submit" value="Log In" /><input type="hidden" name="submitted" /></form>';
if (isset($_POST['submitted']))
{
$pword = hash('sha256', $_POST['password']);
$query = "SELECT pword FROM users WHERE user = 'guest'";
$result = mysql_query($query);
$return = mysql_fetch_assoc($result);
if ($return['pword'] == $pword)
{
pageout();
}
else
{
echo 'You entered the wrong password, if you are not a member, please leave.';
}
}
}
function login_check($username, $uid)
{
}
function pageout()
{
echo('
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="" />
</head>
<body>
<div id="header">
<p>WOOT</P>
</div>
<div id="">
</div>
<div id="navigation">
</div>
<div id="footer">
</div>
</body>
</html>
');
}
?>
存储在数据库中的单个“访客”密码,它访问数据库并检查用户输入的密码与存储在数据库中的密码。我希望在提交表单并且信息正确后,在同一页面上表单消失并显示页面。我该怎么做?如何摆脱表格为新页面腾出空间?
答案 0 :(得分:1)
标题(位置...),或以登录设置为条件的页面显示
答案 1 :(得分:0)
简单地做
在表单的末尾和php代码执行此操作
if(!isset($_POST['s'])){ ?> your form here <?php } else //form handle
答案 2 :(得分:0)
我会让结构看起来略有不同:
//First
if (!isset($_POST['submitted'])) {
//include your form only
} else {
//Check if user submitted correct password
//If password is correct
if ($return['pword'] == $pword) {
pageout();
//OR write pageout code on different page and call header("Location: Yourpage.php");
} else {
//Include form or inform user about password mismatch
}
}
修改。此外,如果您使用标题(&#34;位置:&#34;)功能,请确保您不回显或包含任何输出数据的内容。这将导致Headers已发送错误。