[英]Using a form to display users name on every page till the user logs out
我当前正在创建一个网站,该网站将允许用户仅使用用户名登录,不需要密码。 一旦用户在表单中输入了他们的名字,他们的名字就应该被放置在他们随后访问的所有页面上,直到他们注销为止。
我对此有问题,1)无法在浏览器中正确显示( 我将在下面提供图像 )2)无法将我转发到主页。
<?php
session_save_path("/aber/sec17/public_html/cs25010/tmp");
session_start();
if ($username == NULL) {
if (isset($_POST['submit'])) {
$_SESSION["username"] = $_POST["username"];
header("Location: home.php");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Sean Coyne's Food Shop</title>
<link href="style.css" type="text/css" rel="stylesheet"/>
<link rel="icon" type="image/x-icon" href="images/favicon.ico" />
<meta name="description" content="Welcome to Sean Coyne's Food Shop" />
</head>
<body>
<div id="page">
<div id="logo">
<img src="images/logo.jpg" alt="Sean Coyne's Food Shop"
title="Sean Coyne's Food Shop" width="400px" height="70px"/>
</div>
<div id="nav">
<div id="menu">
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="database.php">Products</a></li>
<li><a href="drink.php.html">Offers</a></li>
<li><a href="about.php">About Us</a></li>
<li><a href="findus.php">Where to find us</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</div>
</div>
<div id="main">
<h1>Welcome to Sean Coyne's Food Shop</h1>
<h2>Please Log In below:</h2>
<br></br>
<div id="login">
<?php
echo '<form action="home.php" method"post">
<input type="text" name="username" text="input username"
placeholder="Username" required>
<input type="submit" name="submit" value="submit" />
</form>';
?>
</div>
</div>
</div>
</body>
</html>
这是登录页面的屏幕截图:
不用引入表格标签“ php”即可改变这一点;
<?php
echo '<form action="home.php" method"post">
<input type="text" name="username" text="input username"
placeholder="Username" required>
<input type="submit" name="submit" value="submit" />
</form>';
?>
为了这:
<form name="form" action="" method="POST">
<input type="text" name="username" text="input username" placeholder="Username" required />
<input type="submit" name="submit" value="submit" />
</form>
如果这是您的完整文件,则您可能需要检查if条件。 替换条件:
if ($username == NULL)
有:
if (empty($_SESSION['username']))
并尝试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.