Sign In
Username: Password: Sign In
<?php
session_start(); // Start a new session or resume the existing one
// This would be in your login handling script
if (isset($_POST[‘username’]) && isset($_POST[‘password’])) {
$username = $_POST[‘username’];
$password = $_POST[‘password’];
// Validate credentials against database (this is just an example)
if ($username == ‘expectedUsername’ && $password == ‘expectedPassword’) {
$_SESSION[‘user_is_logged_in’] = true;
header(‘Location: protected_page.php’);
exit;
} else {
echo „Invalid username or password.“;
}
}
// This would be at the start of each protected page
if (!isset($_SESSION[‘user_is_logged_in’])) {
header(‘Location: login_page.html’); // Redirect to the login page
exit;
}
?>
Færðu inn athugasemd