Is it possible to use PHP to track user sessions and prevent multiple pages from being accessed simultaneously?
To track user sessions and prevent multiple pages from being accessed simultaneously in PHP, you can use session variables to keep track of the user's session ID and restrict access to pages if the user is already logged in on another page. By checking the session ID against a list of active sessions, you can ensure that only one page is accessed at a time per user.
<?php
session_start();
// Check if user is already logged in on another page
if(isset($_SESSION['user_session_id'])) {
if($_SESSION['user_session_id'] !== session_id()) {
// Redirect or display an error message
header("Location: error.php");
exit();
}
}
// Set the user's session ID
$_SESSION['user_session_id'] = session_id();
?>