signin.php:
<?php
include("config.php");
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
if(isset($_POST['login']))
{
$username = mysqli_real_escape_string($con,$_POST['username']);
$password = mysqli_real_escape_string($con,$_POST['password']);
$sel_user = "SELECT * FROM user WHERE username='$username' AND password='$password'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user = 2)
{
$_SESSION['username']=$username;
echo "<script>window.open('index.php','_self')</script>";
}
else
{
echo "<script>alert('Email or password is not correct, try again')</script>";
}
}
?>
的index.php:
<ul class="nav navbar-nav navbar-right">
<li><a href="mypage.html">My Page</a></li>
<li><a href="signup.php">Sign up</a></li>
<li><a href="signin.php">Sign in</a></li>
</ul>
因此,我的index.php,我的页面,注册和登录有三个选项。我想更改登录以在用户登录时注销并在“我的页面”选项的左侧显示我的姓名。我该如何修改我的代码?请不要只说“你需要~~~”。请说明确切添加的位置。谢谢
答案 0 :(得分:1)
取代
<li><a href="signin.php">Sign in</a></li>
你需要
<li>
<?php
if(isset($_SESSION['username'])) { ?>
<a href="signout.php">Sign out</a>
<?php
} else { ?>
<a href="signin.php">Sign in</a>
<?php
} ?>
</li>
那里存在大量的安全问题。您可以通过它的外观在数据库中以纯文本格式存储密码。 你需要解决这个问题。现在强>