I have a side bar with a category "abc". On clicking a pop up div loads asking the user to login or register. Once the user logs in it loads the page "xyz.php". In order to prevent direct access to "xyz.php" I am creating a session variable on post
and checking in the "xyz.php" if the session variable exists:
<?php
session_start();
if (!isset($_SESSION['logged_in']))
header("Location: index.php");
?>
This works perfectly fine and I am able to block direct access to the above link. However, once the user logs in, the page can be accessed directly. In order to prevent this, I am releasing the session variable through:
<?php
session_start();
session_unset('logged_in');
?>
However, I am calling this in the index
file and only if the user visits the home page
the session variable will be unset. How can I unset the session variable across the website once the user has logged in and the page has loaded? The page should load again only after the user has entered the login credentials again. There is no logout
mechanism in place and is not desired.