member.php 页面会话输出上的 php 问题“隐含的用户名”在 login.php 中有效,但未在 member.php 中显示
<html>
<form action="login.php" method="POST">
Username: <input type="text" name="username"><p>
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Login">
</form>
<a href='register'.php>Register Now</a>
</html
上面的代码是 index.html 文件
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("127.0.0.1","root","") or die ("Could not connect `to database");
mysql_selectdb("login") or die ("could not find database");
$query = mysql_query("select * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if($numrows !=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo $_Session['username']="$dbusername ";
echo ", Login successful. <a href='member.php'>Click here to enter the Members area
</a>";
}
else
echo "Incorrect password";
}
else
die ("That username does not exists");
}
else
die ("Please enter a username and password");
?>
上面的代码是login.php,在登录页面上它显示“用户名”登录成功,点击这里进入会员区的链接。
<?php
session_start();
if ($_SESSION['username'] = '$dbusername')
{
echo "Welcome, ".$_SESSION['username']."<br><<a href='logout.php'>Click here</a> to logout!<br>Click<a href='changepassword.php'> here</a> to change your password!";
}
else
die("You must be logged in to see this page");
以上是member.php页面的代码
这是显示输出:
欢迎,$dbusername
点击这里退出!点击这里更改您的密码!
我的问题是它应该如下所示:
欢迎,约翰尼 点击这里退出!点击这里更改您的密码!
一个解决方案会很棒!