delete session

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
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

delete session

Post by hrubos »

I did it to delete session when user logout. But it seems not run, because when I logout, I can enter without loging

Code: Select all

<a href="../index.php?lo=true" class="left_link"> Logout </a><br />

if($lo==true){
 unset($_SESSION[valid_user]);
session_destroy();
}
Last edited by hrubos on Fri Mar 09, 2007 5:14 am, edited 1 time in total.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Check the PHP documentation for session_destroy(). A session has a few facets: the session data, the PHP Session, and the session id. Depending on how you want logouts to be handled, the best option to completely delete the session by setting the global array to array(), unsetting the session cookie to delete the session id, and then calling session_destroy().
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Some bits about the posted snippet: "true" is not the same as true, i.e. all data from submissions (via URL or otherwise) are strings. Next, always always always quote your named array indices ($_SESSION[valid_user])
Post Reply