Force Drupal User Logout

Posted on: 14 January 2010

I had an interesting problem this morning. One of our team had been demonstrating Analytics SEO to a potential reseller, and had forgotten to log out of the site at the end of the demo. He didn't really want to leave them with access to his account (which is a rather powerful administrator-type account), but also didn't really want to phone them and ask them to log out. The reseller is in South Africa, so I can't exactly sneak in and delete their login cookie either.

Fortunately, the site is built using Drupal, which stores logged in user sessions in the database, and only uses the cookie to identify which session a particular user is associated with. The simple way to force out the logged in user is to find the user ID (there are a lots of ways to do this), and then

DELETE FROM sessions WHERE uid = nn;

Simple! I also changed the password just to be on the safe side.