Change something in db when session unsets


Change something in db when session unsets



I build a basic logout script which unsets all sessions, and changes the 1 under the column "loggedin" to 0 in the database. I need to do that so I can check of a user is loggedin, and post this on the users page. When you close of the browser, all sessions etc. are deleted, but the sql query to update the loggedin column will not be executed. How can I fix this?



if there are any questions, please let me know!



Can you help me?



Code:



Logout script:


require "includes/db.php";

ini_set('session.cookie_domain', '.ictsupport.ga' );
session_start();

$username = $_SESSION['auth'];

//SQL to set loggedin to 1
$sqlStat = "UPDATE account_users SET loggedin = 0 WHERE username='$username';";
/*It changes the 1 in the database to a 0 to let the users page know that the user is offline*/

mysqli_query($con, $sqlStat);

session_unset();
session_destroy();





Add a column "LastSeen" to the user table. Whenever a user loads a page, update their "LastSeen" column. When trying to determine which users are active, ignore those who have "LastSeen" more than X Minutes in the past.
– NineBerry
Jun 29 at 17:45





@NineBerry Good idea, but I was wondering if my code could work to (in some way)
– Rick Okkersen
Jun 29 at 17:48





Whatever NineBerry has described seems the better solution in this case
– Rakibul Islam
Jun 29 at 17:55





This is similar: stackoverflow.com/questions/10244604/…
– Rakibul Islam
Jun 29 at 17:55





Possible duplicate of PHP best practice keep track of logged in users
– Rakibul Islam
Jun 29 at 17:56









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift