I don't think it's possible to do this but I know a workaround! Browsers only save 1 realm password so we need to create a new one.
It's a little awkward but it works!
Creat a sub-directory called "logout".
Password protect this directory the same way using .htaccess and .htpasswd files.
Set the username AND password for the directory as "logout".
Then on your other pages, where-ever you want a logout button use the following link::
What this does is basically login as user logout!
In your logout directory you should create an index file with a message "Good bye" or maybe some links or else a redirect to anoth file or directory!
An easier way is simply to remove the fakeuser from the htpasswd.
When the request is made for a user that does not exist, it should log you out from the original request. Doing it the way that you have it, you are giving yourself more work, and the user could overcome the security.
Just redirect the user to
Code:
fake:fake@domain.com
but don't actually have a user with those details.
If the fakeuser doesn't actually exist but you "logout" as 'him' does it actually overwrite the information stored by your browser?
the problem we had was that if we go right back to the protected directory we were still logged in.
When we redirect with the fake user, should it be to a location inside or outside of the protected directory? As far as I know it needs the same AuthType and AuthName to overwrite the info, or am I way off the mark?
then the browser stores those details and overwrites the original.
Because you actually have a user by the fake name, then they are still logged in but under a different username and password. Effectively, they could still access the protected directory with the fake user and pass.
You must send the user to the protected directory with the fake user and pass, and it must use the same auth files to actually overwrite the details, otherwise you are logged into both directories.
Create a custom 401 error page for the directory, then add a login form etc to the error page.
When the user clicks logout, then they are shown the password prompt again, if they want to log in again they can, otherwise they click cancel and see the 401 error page.
What you are trying to acheive is a workaroud, not the actual way that this is supposed to be. Htaccess does not support a "logout" function so logging in as another user defeats the security that htaccess provides as you need to do other server side checks to make sure that the fake user does not access the directory.
For this reason, you don't want to login as an actual user but instead trick the browser into requiring the username and password again by sending incorrect details.
Ok, think i'm getting it.
One problem I had was that I was logging out as fakeuser:fakepass but if I tried to access the protected directory I was still logged in as realuser.
Usually, browsers does not save information if they receive a 401 response. Most browsers just continue using the old credentials when they receive a 401 for new ones. //Daniel
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.