这是问题所在,我正在尝试使用正确的信息登录(通过phpmyadmin进行三重检查),但它所做的只是重定向回登录页面,就像信息不正确一样。
登录表格(页面顶部)
<?php
session_start();
include "includes/class.users.php";
if(isset($_POST['login'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$users->login($email, $password);
}
?>
登录表格
<form method="POST" action="" name="login">
<div id="wrappermiddle">
<h2>Login</h2>
<div id="username_input">
<div id="username_inputleft"></div>
<div id="username_inputmiddle">
<input name="email" type="text" id="myusername" placeholder="Email Address">
<img id="url_user" src="./images/mailicon.png" alt="">
</div><!--ends username_inputmiddle-->
<div id="username_inputright"></div>
</div><!--ends username_input-->
<div id="password_input">
<div id="password_inputleft"></div>
<div id="password_inputmiddle">
<input name="password" type="password" id="mypassword" placeholder="Password">
<img id="url_password" src="./images/passicon.png" alt="">
</div><!--ends password_inputmiddle-->
<div id="password_inputright"></div>
</div><!--ends password_input-->
<div id="submit">
<input type="image" src="./images/submit.png" name="login" value="Login">
</form>
类.用户.php
<?php
include "class.database.php";
class Users extends Database {
public function login($email, $password) {
$stmt = $this->mysqli->prepare("SELECT email, password FROM members WHERE email = ? AND password = ? LIMIT 1");
$stmt->bind_param('ss', $email, $password);
$stmt->execute();
$stmt->bind_result($email, $password);
$stmt->store_result();
if($stmt->num_rows == 1) {
while($stmt->fetch()) {
session_start();
$_SESSION['loggedin'] = true;
header("Location: dashboard.php");
}
} else {
return false;
}
$stmt->close();
$stmt->free_result();
}
}
$users = new users();
?>
仪表板.php在顶部
<?PHP
session_start();
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
} else {
header ("Location: index.php");
}
?>
编辑 - 我尝试使用错误的密码登录,但出现错误 - 出现错误
当我使用正确的信息登录时,如果只是刷新登录页面。
我认为
问题是您在呈现某些 html 后设置标题。
我的方法是包含在登录页面中
if ($_SESSION['loggedin] = true) {
header("Location: dashboard.php");
} else {
login page
}