我正在设计一个网站与登录页面,登录部分和从 db 获取的内容工作正常, 但是我想登录后在主页上显示用户名。我用的 session start ()没有效果,用户名还是没有显示。我查过类似的问题,但都不是我想要的答案。
下面是代码:
$email = mysqli_real_escape_string($con,$_POST['user']);
$pass = mysqli_real_escape_string($con,$_POST['pass']);
$sel_user = "select * from admins where email='$email' AND password='$pass'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0)
{
$_SESSION['email']=$email
echo "<script>window.open('index2.html','_self')</script>";
}
else {
echo "<script>alert('Email or password is not correct, try again!')</script>";
}
index2.html :
<?php
session_start();
?>
<div class="inline-block">
<h5 class="no-margin"> Welcome </h5>
<h4 class="no-margin"> <?php echo $_SESSION['email']; ?> </h4>
<a class="btn user-options sb_toggle">
<i class="fa fa-cog"></i>
</a>
</div>