How to end a session with a click?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

How to end a session with a click?

Post by Citizen »

What code would I need to run in order to allow the user to click a button and end the session to log out?

Thanks,
-Cit
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

To really log out, they would need (at least) an interaction with the server so it can destroy the session data associated with them. The quick and dirty log out would use Javascript to erase the browser's session cookie reference and change the URL to not have the session id in it.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

So I'd have to use a form?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not absolutely. The URL you hit could be specifically built to destory the session data, or know to destroy it from the request data, or some other such things.
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

So it would be a good idea to have a link like http://link.com/logout?log=out and open it in _blank with the end session code in it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

provided your script responds to such a url, sure, although _blank isn't needed..
Post Reply