Php 登录后回显Hello用户名

Php 登录后回显Hello用户名,php,html,login,Php,Html,Login,用户被要求的第一件事是登录;如果登录成功,则将用户发送到index.php(如果没有);他们被要求重新输入他们的详细信息 我希望用户名在用户登录后显示在index.php上 因此,在index.php文件中使用echo函数从登录名中获取用户名 //check to see if they match if($username==$dbusername&&$password==$password) { $_SESSION['username']=$username; ech

用户被要求的第一件事是登录;如果登录成功,则将用户发送到index.php(如果没有);他们被要求重新输入他们的详细信息

我希望用户名在用户登录后显示在index.php上

因此,在index.php文件中使用echo函数从登录名中获取用户名

//check to see if they match
if($username==$dbusername&&$password==$password)
{
$_SESSION['username']=$username;
    echo "Welcome '.$username.'";
    header('Location: nindex.php');
    die(); 
}
else
echo "incorrect password";

}
else
    die("That user does not exist");
}
else
    die("please provide a  username and password");

?>

在调用“header”之前,您不能回显任何输出,否则将出现该错误

echo命令需要在被调用的页面nindex.php中执行

header("Refresh: 5; url=index.php");
echo "Welcome '" . $username . "'";
exit;#should be added so rest of page doesn't load.


并删除回音欢迎“$username”;从您的登录页面。如果您希望它显示一次,我可以根据您的需要修改我的答案。

您不能在标题行之前回显任何内容。您有$password==$password。这永远不会是错误的。此外,您是否以明文形式存储密码?您是否真的知道,由于您的代码,您可以只使用正确的用户名而不使用密码登录到您的系统?我只发布了一段代码,我已经对其进行了测试;用户需要用户名和密码是的,如何在index.php页面中回显命令?我需要在index.php中执行此操作,而不是在login.phpy中执行此操作。您可以在index.php中执行此操作,只需将index.php改为login.php即可simple@SH我不明白你在问什么。编辑这个问题,请让我知道这是否更清楚,这个脚本将在login.php中,所以一旦您登录,您希望页面将您带到index.php并显示您的姓名?解析错误:语法错误,意外的“{”在线4@SH抱歉,请在之前添加另一个{在if上isset@SH没问题,很高兴我能帮上忙。它显示在页面顶部,这会影响CSS。我如何才能在左侧菜单中显示用户名?@SH在html中将ifisset移动到左侧菜单,并确保在其周围像这样附上php标记`
if(isset($_GET['id'])){
echo 'Welcome '.$_GET['id'];
}else {
echo '(write) a 404 page';

}
header("Refresh: 5; url=index.php");
echo "Welcome '" . $username . "'";
exit;#should be added so rest of page doesn't load.
echo "Welcome '" . $username . "'";?>
<meta http-equiv="refresh" content="5; url=index.php" />
<?php
exit;#should be added so rest of page doesn't load.
if(isset($_SESSION['username'])){
    echo "Welcome '{$_SESSION['username']}'";
}