you need to be logged in to log out

I installed various window managers (Awesome, dwm, etc.) from which I am not able to log out back to the login screen (gnome-session) in order to switch to another window manager. I need to reboot to do that, which is a waste of time (and can lead to data corruption).

..neither did this:

Is there a quick way to log out back into Gnome's session manager from a non-Gnome desktop manager using a terminal emulator? I know that CTRL+ALT+BACKSPACE can be configured to restart X, but I'm looking for the easiest way to log out.


Updated: Login/Logout Method for Basic Authentication

The situation: a kiosk application where people in the community would log in to a web page, request some materials, then log out again. The users are all in our Active Directory login system. How can you construct it so that a user can log out, and the next log in, without forcing them to close and re-open the browser?

Not so simple, but doable. Here’s the method I used with Linux, PHP and JavaScript. Bear in mind, the process is that a user logs in, does some work, and then clicks a link to log out. This will go to a new page we’ll create called “logout.php”.

First you have to set up your .htaccess file to properly lock users out until they log in with their Active Directory or LDAP credentials. Here’s what my file looks like, sanitized for my protection:

AuthName "Media Manager"

Fill in a couple of blanks here. You will absolutely need the cooperation of whoever manages your ldap server to get the “yourusername” and “yourpassword” entries. These will be credentials that allow your application to talk to the ldap server. Other values in the AuthLDAPURL string may vary too. This is probably the single hardest part — untangling the cryptic parameters you need to pass to get the information you need.

But once you have it, save it into the subdirectory your web application lives in as .htaccess.

Would you be surprised to learn that you have to do this differently in Internet Explorer than you do in Firefox? Me neither. But in this case, the IE version is simpler. You can do it with a simple JavaScript command. First, you need to have jQuery installed.

Once you have it, create a file called “logout.php” and put it in the same directory as your .htaccess file. start out the file with the usual opening <php?, and add this code:

// Check username and password:

if (isset($_SERVER['PHP_AUTH_USER']) &9amp; isset($_SERVER['PHP_AUTH_PW']))<

// Does the user want to login or logout?

// reset is a special login for logout

We’re setting up some basic variables, setting initial statuses to false, and then pulling out the username and password from the credentials the user has already entered when they originally logged in to use your application.

If the username and password are both “reset,” bogus entries that I’ll explain below, the user is attempting to log out with an ajax request. If that’s the case, then we generate one set of HTML. It can be as simple as:

// The user clicked on "Logout"

print 'You are now logged out.';

The first time a user hits the logout.php page, he’ll already be logged in, and his credentials are sitting in the cache. The value of $LoginSuccessful will have been set to “true” in the initial block of PHP code, and so you’ll need to give them something else.

The real credentials passed in — which by definition they are, since your user had to log in to get here in the first place — means they’ve clicked your link to “logout.php” for the first time and you need to show them the entire page.

Call in the jQuery libraries:

<script src="http://tom-mcgee.com/archives/js/jquery-1.6.3.min.js" type="text/javascript">9lt;/script9gt;

<script src="http://tom-mcgee.com/archives/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript">9lt;/script9gt;

Then, drop this into your <head9gt; section. Note that this has been updated:

<script type="text/javascript" language="javascript">

//not an IE browser

With the latest versions of Firefox, the call to ClearAuthenticatonCache didn’t throw an error, so the catch block was never called. By reversing the order, it now works in IE9 and Firefox 15.

The jQuery ajax call I mentioned above is made in the “catch” block to the same page you’re on, passing in the bogus username/password combination of “reset” and “reset”, then sending a 401 status code — “Not Authorized.” This is what has the effect of clearing out the Firefox authentication cache by replacing the values that work — the user’s original login and password — with values that won’t — “reset” and “reset”.

It’s triggered by a single line in the HTML of the page:

The last thing that’s needed is a way to catch other kinds of requests, such as the user entering the wrong combination three times, or giving up.

header('WWW-Authenticate: Basic realm="Top-secret area"');

header('HTTP/1.0 401 Unauthorized');

print "Sorry, login failed!\n";

print '<a href="http://' . $CurrentUrl . '">Try again</a9gt;';

Either way, the user should be logged out, and a new (correct) login and password will have to be passed in for the application to work again. Here’s the complete code of the page.

// Check username and password:

if (isset($_SERVER['PHP_AUTH_USER']) &9amp; isset($_SERVER['PHP_AUTH_PW']))<

// Does the user want to login or logout?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title9gt;Example | Logged Out</title9gt;

<script src="http://tom-mcgee.com/archives/js/jquery-1.6.3.min.js" type="text/javascript">9lt;/script9gt;

<script src="http://tom-mcgee.com/archives/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript">9lt;/script9gt;

// The user clicked on "Logout"

print 'You are now logged out.';

else if ($LoginSuccessful)<

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title9gt;Example | Log Out</title9gt;

<script src="http://tom-mcgee.com/archives/js/jquery-1.6.3.min.js" type="text/javascript">9lt;/script9gt;

<script src="http://tom-mcgee.com/archives/js/jquery-ui-1.8.16.custom.min.js" type="text/javascript">9lt;/script9gt;

<script type="text/javascript" language="javascript">