Let's say the User named Michael is registered, and is in our database in table named users.
Michael browses my site, and while he does so, I delete his user from the table. My login system works with sessions.
After user Michael was deleted from the database, the browser can browse the website with "Michael" until the session ends.
That's because after the session processes, it doesn't change unless you check every time.
My solution that may increase a huge engine load because of too many queries / requests:
In session.inc.php add a checker:
if (isset($_SESSION['user']))
{
$check = $pdo->prepare("SELECT * FROM users WHERE user_name = :user")
$check->execute(array( ":user" => $_SESSION['user']));
if (!$check->rowCount())
{
session_destroy();
}
}
It will check if theres a row with the exact same username he is logged in currently with the session, if not, it will destroy the session.
Question:
Will that solution cause a large engine load, if my website gets many browsing users?
Is there a better method of doing this?
SELECT COUNT(*) FROM users WHERE user_name = :usershould be enough. Faster than fetching all data.