Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does "Logout Everywhere" work in PHP?

Tags:

php

logout

I just found out that stackoverflow has a link to logout every logged computers.

So..I thought about how to implement same functionality in PHP. I came up with using session_set_save_haldner to control write() method. In write() method, I can make a session file start with user's username. For example, a user john might have session files john_kdkajdkak, and john_29039dla. When John clicks "Logout Everywhere", I can write a code that finds filenames start with "john" then remove them to clear sessions.

are there any other better solutions? How did you implement it if you already made it work?

like image 519
Moon Avatar asked Feb 21 '11 03:02

Moon


People also ask

How do I prevent an auto logout session in PHP?

Use password_hash and password_verify instead.

How do I logout of HTML PHP?

The process is: - Click Log In button on index. php - Enter username and password to access authenticate index file. - Click log out button, which references the logout. php file - it SHOULD clear the cache and return the user to the top level index.


1 Answers

Use a database to persist session data.

Using session_set_save_handler you can roll your own database storage backend for user sessions - a sessions that has a user_id foreign key, related to the users table. A "logout everywhere" button would trigger simple DELETE FROM sessions WHERE user_id = 1234 and invalidate every session for the user.

You can also easily add in additional columns to the session table - to store the IP address of the session, for instance, so users can see where other sessions are logged in from.

Use a database for flexibility and performance.

like image 131
leepowers Avatar answered Sep 28 '22 06:09

leepowers