watch.twip-network.org/pages/global/login.html
2024-01-25 20:40:16 +01:00

42 lines
1.4 KiB
HTML

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
global $mysqli;
// Handle login form submission
$email = $_POST['email'];
$password = $_POST['password'];
// Validate login credentials and fetch user details
$query = "SELECT id, username, password, email, isAdmin FROM users WHERE email = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($user_id, $user_username, $user_password, $user_email, $user_isAdmin);
// Fetch the result
if ($stmt->fetch() && password_verify($password, $user_password)) {
$_SESSION['user_id'] = $user_id;
$_SESSION['user_username'] = $user_username;
$_SESSION['user_email'] = $user_email;
$_SESSION['user_isAdmin'] = $user_isAdmin;
// Redirect to the main domain after successful login
header('Location: / ');
exit();
} else {
echo "Invalid email or password.";
}
// Close the statement
$stmt->close();
}
?>
<!--PAGENAME=Login-->
<h2>Login</h2>
<form action="" method="post">
<input type="email" name="email" id="email-field" placeholder="E-Mail" required>
<input type="password" name="password" id="password-field" pattern=".{3,32}" placeholder="Password" required>
<input type="submit" name="login" value="Login">
<a href="/register">Don't have an account?</a>
</form>