Skip to content

Commit

Permalink
Fixed Login Session Issue
Browse files Browse the repository at this point in the history
Fixed the issue where can access the Todo list page without logging in.
  • Loading branch information
Abhijitkr authored Aug 9, 2023
1 parent 40af5f1 commit 945f2db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
$_SESSION['user_id'] = $user['id']; // Store the user_id in the session

echo "<script>alert('Login successful!');</script>";
echo "<script>window.location.href = 'todolist.php';</script>";
exit();
} else {
echo "<script>alert('Invalid email or password.');</script>";
echo "<script>window.location.href = 'signin.php';</script>";
}

$stmt->close();
$mysqli->close();
} else {
echo "<script>alert('Please fill in all the required fields.');</script>";
echo "<script>window.location.href = 'signin.php';</script>";
}
$stmt->close();
$mysqli->close();
}
?>
1 change: 1 addition & 0 deletions signin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</div>
<script>
// Function to toggle between Sign Up and Login forms
function toggleForms() {
var signUpForm = document.getElementById('sign-up-form');
Expand Down
10 changes: 10 additions & 0 deletions todolist.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<?php
session_start();

// Check if the user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: signin.php"); // Redirect to the login page
exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
Expand Down

0 comments on commit 945f2db

Please sign in to comment.