• Explanation: Secure login systems with user authentication and PHP sessions.
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($_POST["username"] == "admin" && $_POST["password"] == "password") {
$_SESSION["loggedin"] = true;
header("Location: dashboard.php");
} else {
echo "Invalid login credentials";
}
}
?>
<form method="POST">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
• Logic: This login form authenticates users based on predefined credentials.