PHP: Logout From All Devices on Password Change

To logout users from all devices when the password is changed in PHP, here we will create a good and easy approach to create the script.

Here are some major steps which we will follow,

  1. At the time of login we will store a random number associated with the user id into the DB and session.
  2. Store IS_LOGIN key as true at the time of user login.
  3. At the time of change password, if you select logout from all devices it will delete random value from DB.
  4. Create a JS file where it will check status of the user at every 5 seconds.
  5. Create a check status file where query will check the random value is available or not.
  6. At last, when we will logout it will destory all session stored data and delete random value from DB.
PHP: Logout From All Devices on Password Change
PHP: Logout From All Devices on Password Change

Note: You can download complete file at the end of the article

Now we will start with some core files source code which we use to process the above steps,

DB Connection

Login Script

Here we store the random integer and user ID into the database. And will store the same data on session to manage further operations.


After login, you will redirect to the dashboard page. Here we have included our custom JS, logout, and change password page.

Custom JS with Check Status PHP file

Here this file will check the user status every 5 seconds.

On Change Password

At the time of changing the password, if the user checks on log out from all devices then it will delete that random value for that particular user.

Download complete file

A complete working script of implementing logout from all devices in PHP.

Hope you all will understand the complete concept of Logout From All Devices on Password Change using PHP.

To know more about PHP, you can check PHP official site.

Please let me know if you will face any issues with implementation.

Happy Coding..!

Was this article helpful?
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
Posts created 188

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top