To log out 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 in the DB and session.
  2. Store IS_LOGIN key as true at the time of user login.
  3. At the time of changing the password, if you select logout from all devices it will delete a random values from DB.
  4. Create a JS file where it will check the status of the user every 5 seconds.
  5. Create a check status file where a query will check whether the random value is available or not.
  6. At last, when we will log out it will destroy all session stored data and delete the random values 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 file’s source code which we use to process the above steps,

DB Connection

Login Script

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

Dashboard

After login, you will redirect to the dashboard page. Here we have included our custom JS, log out, 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.

[wpdm_package id=’4616′]

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’s official site.

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

Happy Coding..!

Was this article helpful?
YesNo

By Bikash

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.

2 thoughts on “PHP: Logout From All Devices on Password Change”

Leave a Reply

Your email address will not be published. Required fields are marked *