登录后点击登录链接,需要再次登录。
会议节省了
我插入标题重定向到其他页面,如果我在登录后单击登录页面但仍然相同。
这是我的登录过程php
<?php
ini_set("session.save_path",$_SERVER["DOCUMENT_ROOT"]. "../../sessionData");
session_start();
include 'database_conn.php'; // make db connection
?>
<!DOCTYPE html>
<html>
<head><title>Login Process</title></head>
<link rel="stylesheet" type="text/css" href="test1.css">
<meta charset = "utf-8">
<body>
<div id="title">
<p><h1>Tyne Events</h1></p>
</div>
<div id="wrapper">
<div id="navbar" >
<ul class="nav">
<li><a href="home.html">Home</a></li>
<li><a href="findoutmore.php">Find out more</a></li>
<li><a href="offer.html">Offer</a></li>
<li><a href="credit.html">Credit</a></li>
<li><a href="admin.php">Admin</a></li>
<li><a href="login.php">Login</a></li>
<li>
<form class="formright">
<input type="text" placeholder="Search">
<button type="submit">Search</button>
</form>
</li>
</ul>
</div>
<div id= "content">
<?php
$username = filter_has_var(INPUT_POST, 'userName') ? $_POST['userName']: null;
$passWD = filter_has_var(INPUT_POST, 'pwd') ? $_POST['pwd'] : null;
$username = trim($username);
$passWD = trim($passWD);
$errorList = array();//create an empty array
if (empty($username)){
$errorList[]="<p> You have not enterd Username</p>\n";
}
if (empty($passWD)){
$errorList[]="<p>You have no enter password</p>\n" ;
}
if(!empty($errorList))
{
echo "<p><em>The following problem(s):</em></p>\n";
for ($a=0; $a < count($errorList); $a++)
echo "$errorList[$a] \n";
}
else{
/* Query the users database table to get the password hash for the username entered by the user in the logon form */
$sql = "SELECT passwordHash FROM te_users WHERE username = ?";
// prepare the sql statement
$stmt = mysqli_prepare($conn, $sql);
/* Bind the $username entered by the user to the prepared statement. Note the “s” part indicates the data type used – in this case a string */
mysqli_stmt_bind_param($stmt, "s", $username);
// execute the query
mysqli_stmt_execute($stmt);
/* Get the password hash from the query results for the given username and store it in the variable indicated */
mysqli_stmt_bind_result($stmt, $passWDHash);
/* Check if a record was returned by the query. If yes, then there was a username matching what was entered in the logon form and
we can now test to see if the password entered in the logon form is the same as the stored (correct) one in the database. */
if (mysqli_stmt_fetch($stmt)) {
$_SESSION['uName'] = $username;
// password was correct
if(password_verify($passWD , $passWDHash)){
$_SESSION['logged-in'] = true;
echo "<p>password correct</p>\n";
}
else {
echo "Password incorrect.";
}
}
else {
echo "<p>Sorry we don't seem to have that username.</p>";
}
mysqli_stmt_close($stmt);
}
mysqli_close($conn);
if (isset($_SESSION['logged-in']) && $_SESSION['logged-in'] == true)
{
echo "<p>".$_SESSION['uName']."</p>\n";
echo "<p><a href=\"#\">Admin Link </a>\n";
echo "<p><a href=\"logout.php\"> Log out here </a></p>";
}
?>
</div>
</body>
</html>
这是我的登录页面,我使用if(isset($ _ SESSION [&#39;登录&#39;])&amp;&amp; $ _SESSION [&#39;登录&#39;] = = true)检查登录。
<?php
ini_set("session.save_path",$_SERVER["DOCUMENT_ROOT"]. "../../sessionData");
session_start();
if (isset($_SESSION['logged-in']) && $_SESSION['logged-in'] == true)
{
header(' Location :admin.php');
}
include 'database_conn.php'; // make db connection
?>
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<link rel="stylesheet" type="text/css" href="test1.css">
<meta charset = "utf-8">
<title>
</title>
</head>
<body>
<div id="title">
<p><h1>Tyne Events</h1></p>
</div>
<div id="wrapper">
<div id="navbar" >
<ul class="nav">
<li><a href="home.html">Home</a></li>
<li><a href="findoutmore.php">Find out more</a></li>
<li><a href="offer.html">Offer</a></li>
<li><a href="credit.html">Credit</a></li>
<li><a href="admin.php">Admin</a></li>
<li><a href="login.php">Login</a></li>
<li>
<form class="formright">
<input type="text" placeholder="Search">
<button type="submit">Search</button>
</form>
</li>
</ul>
</div>
<div id= "content">
<div id="login">
<form method = "post" action="logonProcess.php">
<fieldset>
<legend>LOGIN</legend>
<table>
<tr>
<td>User Name </td>
<td><input type="text" name="userName"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pwd"></td> 45$Qr87$482d
</tr>
</table>
<input type="submit" value="Logon">
</fieldset>
</form>
</div>
</div>
</body>
</html>