Итак, я настроил страницу, которая позволяет пользователю либо войти в систему, либо зарегистрироваться. Регистрация работает нормально, хотя вход в систему просто обновляет страницу, когда вводится правильная информация для входа в систему, и когда я ввожу неверную информацию для входа, он перенаправляет в login.php без ошибок, которые отображаются. Я пытался удалить свои куки и т. Д., Которые, кажется, решают проблемы других людей, хотя ясно, что это что-то более глубокое.
Форма входа (index.php):
<form class="navbar-form navbar-right" method="POST" role="search" action="pages/login.php">
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email">
<input type="password" class="form-control" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-success">Login</button>
</form>
Форма регистрации (index.php):
<form method="POST" class="form-signin" action="functions/register.php">
<h3 class="text-center">Signup Here!</h3>
<input type="text" name="firstname"placeholder="First Name"class="form-control" required>
<input type="text" name="lastname"placeholder="Last Name"class="form-control" required>
<input type="text" placeholder="Username" name="username"class="form-control" required>
<input type="text" placeholder="Email" name="email"class="form-control" required>
<input type="password" placeholder="Password" name="password" class="form-control" required>
<input type="submit" value="Signup" class="btn btn-success" style="width:100%;">
</form>
Log-in.php:
<?php
session_start();
include '../functions/db.php';
// Escape email to protect against SQL injections
$email = $mysqli->escape_string($_POST['email']);
$result = $mysqli->query("SELECT * FROM tbluser WHERE email='$email'");
if ( $result->num_rows == 0 ){ // User doesn't exist
$_SESSION['message'] = "User with that email doesn't exist!";
}
else { // User exists
$user = $result->fetch_assoc();
if ( password_verify($_POST['password'], $user['password']) ) {
$_SESSION['email'] = $user['email'];
$_SESSION['first_name'] = $user['first_name'];
$_SESSION['last_name'] = $user['last_name'];
$_SESSION['user_name'] = $user['user_name'];
$_SESSION['user_Id'] = $user['user_Id'];
// This is how we'll know the user is logged in
$_SESSION['logged_in'] = true;
header("location: home.php");
}
else{
printf("Errormessage: %s\n", $mysqli->error);
$mysqli->close();
die();
}
}
?>