Click to See Complete Forum and Search --> : How to Log out from a website ???
Hi there....
I used UNIX htaccess for Log in to my web page. Inside my code I use MYSQL but everytime I closed the seeion for MYSQL.
Now my goal is to logo out from unix server and once I do that no matter how many same web page I have open will be logged out or inactive as for example in hotmail accout if you log out once you cannot have access for the other hotmail window if there is any open one. How to do that?
Thank you.
stolzyboy
07-17-2003, 04:16 PM
either which way you do it .htaccess or sessions, when you close your browser window, the session should be killed, regardless if they have windows open to something else or not, or maybe i am confused by your post
goldbug
07-17-2003, 05:41 PM
stolzyboy: the way I read it... he wants to have Basic Authentication (htaccess) "un-authenticate" a user, just like you might with PHP-controlled access when you might terminate a session (if that makes sense). As far as I know, it can't be done (easily). If anybody knows a way, please speak up.. I'd love to know!
yelvington
07-19-2003, 09:58 AM
If anybody knows a way, please speak up.. I'd love to know!
See the PHP manual page on HTTP Basic authentication, which says:
Both Netscape Navigator and Internet Explorer will clear the local browser window's authentication cache for the realm upon receiving a server response of 401. This can effectively "log out" a user, forcing them to re-enter their username and password. Some people use this to "time out" logins, or provide a "log-out" button.
And read the caveats that follow.
Thank you for your suggetion. I am kind of ne in web designing. So could you please expalin me in detail (code might be helpfull) so that I can understand the process better. For example, Once you logout from hotmail if you have any other page open for the same hotmail account, that will be inactive, mean that logout will have tatal control of the other pages. So how to do that using UNIX server? Thank you.
yelvington
07-19-2003, 01:24 PM
It's not a server issue. Authentication/access control works differently than you might think.
You never actually "log in." Instead, here is what happens:
Browser requests protected page
Server responds with authentication challenge
Browser displays login/password dialog
User submits information
Browser resubmits the page request, passing login/password along with the request
Browser KEEPS the login/password and resubmits it for EVERY subsequent request to that domain
Here's the important part. To "log out," you have to force the browser to "forget" the username/password combination.
That's what the PHP manual is talking about. You call the header() function to set the server response code to 401. HTTP response code 401 means "unauthorized." When Netscape and IE get that header, they "forget" any login/password you previously entered.
There is example code on the manual page, in the comments area.
Thank you for your informatiom. Could you please let me know the exact web address of the PHP manual where the header() function is being talked.
Where is the comment area by the way?
Thank you.
Still waiting for source information about the header() and it's implimentation for log out from a web page. ALso plese tell me the about the comment area.
Please help!!! Thank you.
I tried the following code:
<?php
header("WWW-Authenticate: Basic realm=\"My Realm\"");
header('status: 401 Unauthorized');
print "Logout Successfull";
?>
Now I am getting a the same window for filling up the user id and password that I got first to log in to my web site as I used .htaccess file in side the MainPage directory.
And if I press cancel it's giving me:
Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
If I press ok without inputting any thing it gives me:
"Logout Successfull"
Even I tried to fillup the user ID and password and press ok it gives me "Logout Successfull". I assume it's asking me the same user ID and Password that I used for the first login to for .htaccess file.
But I don't want none of the above situations.
Let me tell you my goal. I think that might help you to understand what I really want to do.
I want to use some php code that will log me out from this web site and no matter how many pages are open from the same web sire (Those will be inactive). I mean you have to login again to get atarted again. Just think about hotmail. If it has open several pages from same user account. If you logout one of the page the others are required t olog in again on order to do something.
Hope you understand. Plese let me know your advice.
ksandom
07-21-2003, 07:37 AM
I think you are gonna be better using sessions here. Part of what I posted on your other thread.If I'm right you'll be better off user something like $_SESSION. You'll also want to look at Session_Start(), Session_Name.
Thank you for your reply. I like to inform you that I am a beginner in this field. So if you read my previous posting where I explain what I exactly want, I would be glad if you give me some code example and I believe that will help me regarding headred and session. Thank you.
ksandom
07-22-2003, 01:32 AM
Have a really good read through this:
Newbies forum FAQ + Bookmarked threads (http://www.phpbuilder.com/board/showthread.php?s=&threadid=10245251)
It won't completley answer your question, but it should hlp clear things up.
There is a lot of information about this in the forums here. Use the search to search for session. You will see lots of examples of people having trouble, but you will be able to see why they don't work and how to fix them. I think this is probably a better way for you to learn rather than me jus tmaking up some code specially for you which you would end up having to modify anyway to do what you want.
If you see "session_register('varname')". This is the old way of doing it, don't bother. If you see "$_SESSION['varname']". This is the new way... YIPPEE ;)
Some ones that will help:
PHP.NET Manual - Sessions (http://php.net/session) This looks to be current. Have a look at the example about half way down. It's very simple and to the point. It also looks current.
[ RESOLVED I THINK ] i'm pretty sure ig ot this: $quetion = "Cookies and Sessions"; (http://www.phpbuilder.com/board/showthread.php?s=&threadid=10248071&highlight=session) This link is probably obsolete now that the PHP.NET Manual is listed above, but you might find some useful stuff in here.
Good luck.
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.