我不知道发生了什么。它是第一次工作,但突然停止了。
创建一个注册和登录系统,确定。经过测试,运作良好。最初是意外错误,现在显示如下:
致命错误:未捕获错误:在C:\ xampp \ htdocs \ playing \ index.php:91中的bool上调用成员函数close()堆栈跟踪:#0 {main}抛出在C:\ xampp \ htdocs中第91行的\ playing \ index.php
<?php // Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: welcome.php");
exit;
}
// Include config file
require_once "common/server.php";
// Define variables and initialize with empty values
$Email = $Password = "";
$email_err = $password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if Email is empty
if(empty(trim($_POST["Email"]))){
$email_err = "Please enter Email.";
} else{
$Email = trim($_POST["Email"]);
}
// Check if Password is empty
if(empty(trim($_POST["password"]))){
$password_err = "Please enter your Password.";
} else{
$Password = trim($_POST["password"]);
}
// Validate credentials
if(empty($email_err) && empty($password_err)){
// Prepare a select statement
$sql = "SELECT id, Email, Password, Gender FROM users WHERE Email = ?";
if($stmt = $conn->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bind_param("s", $param_Email);
// Set parameters
$param_Email = $Email;
// Attempt to execute the prepared statement
if($stmt->execute()){
// Store result
$stmt->store_result();
// Check if Email exists, if yes then verify Password
if($stmt->num_rows == 1){
// Bind result variables
$stmt->bind_result($id, $Email, $hashed_password, $Gender);
if($stmt->fetch()){
if(password_verify($Password, $hashed_password)){
// Password is correct, so start a new session
session_start();
// Store data in session variables
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["Email"] = $Email;
if ($Gender=="Male") {
header ("location: assets/step/Step1_Male.php");
} else {
echo "Female";
}
// Redirect user to welcome page
//header("location: success.html");
} else{
// Display an error message if Password is not valid
$password_err = "The Password you entered was not valid.";
}
}
} else{
// Display an error message if Email doesn't exist
echo "No account found with that Email.";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
}
?>
'''