だから私はログインと登録システムを構築しようとしていますが、ログインフォームが送信されると、「ヘッダー(場所:restricted.php)」を除いてすべてのPHPが正常に動作するようです。何も起こらず、エラーも表示されず、送信をクリックするとページが更新されます。
ログインページのコードは次のとおりです。
<?php
include("connection.php");
if (isset ($_POST["submit"]) ) {
$email = $_POST["email"];
$password = $_POST["password"];
$result = mysqli_query($conn, "
SELECT * FROM users WHERE email = '$email' AND password = '$password'
");
$row = $result->fetch_array(MYSQLI_BOTH);
session_start();
$_SESSION["UserID"] = $row["UserID"];
$_SESSION["first_name"] = $row["first_name"];
$_SESSION["last_name"] = $row["last_name"];
$_SESSION["email"] = $row["email"];
$_SESSION["username"] = $row["username"];
$_SESSION["password"] = $row["password"];
header('Location: restricted.php');
}
?>
<!DOCTYPE html>
<html>
<?php
$title = "Sign In";
$css = "";
include('../include/head.php');
?>
<body>
<h2>Log In</h2>
<!--LOGIN FORM-->
<form action="signin.php" method="POST">
Email <input type="text" name="email" /> <br />
Password <input type="password" name="password" />
<br /> <br />
<input type="submit" name="submit">
</form>
<a href="signup.php">Sign Up</a>
</body>
</html>
制限付きページのコードは次のとおりです。
<?php
session_start();
if ( isset($_SESSION["UserID"] ) ) {
} else {
header('Location: signin.php')
}
?><!DOCTYPE html>
<html>
<head>
<title>Restricted Page</title>
</head>
<body>
<p><?php echo 'Welcome ' . $_SESSION["first_name"]; ?></p>
</body>
</html>
どんな助けでも大歓迎です。