techker Posted October 25, 2008 Share Posted October 25, 2008 hey guys i have a script i did and i need help with my logout? im using sessions. <?php session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); }?> Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/ Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 Uhh...I hope you're not using session_register, session_unregister, and session_is_registered, considering that they're horribly deprecated. Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674682 Share on other sites More sharing options...
techker Posted October 25, 2008 Author Share Posted October 25, 2008 why is that? Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674685 Share on other sites More sharing options...
kenshintomoe225 Posted October 25, 2008 Share Posted October 25, 2008 When you load your logout page, make a call to session_destroy(); That'll end the session completely. Also, its usually not good practice to make use of deprecated functions as they aren't supported, and can potentially cause problems with newly added functions, or other parts of your application. Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674688 Share on other sites More sharing options...
techker Posted October 25, 2008 Author Share Posted October 25, 2008 would this be good? <?php session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); session_destroy(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674689 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 They're really deprecated. You should be using the $_SESSION superglobal. Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674691 Share on other sites More sharing options...
techker Posted October 25, 2008 Author Share Posted October 25, 2008 no im thinking of this.. <?php if(isset($submit)) { session_destroy(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674693 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 You need to have a session started before using session_destroy(). Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674697 Share on other sites More sharing options...
techker Posted October 25, 2008 Author Share Posted October 25, 2008 ya they are logged in already. how can i echo the user that just loggin? Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674701 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 session_start() needs to be called on EVERY single page, even the one with session_destroy(). Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674702 Share on other sites More sharing options...
techker Posted October 25, 2008 Author Share Posted October 25, 2008 well it is on the top of every page for security.. and the destroy will be a button on the main page to. with this <?php if(isset($submit)) { session_destroy(); } ?> is there a way to fetch the username? i was thinking to grab it from myusername session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); session_destroy(); } Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674707 Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2008 Share Posted October 25, 2008 Session_destroy() just deletes the session data file. Any $_SESSION variables in the current script will cause the session data file to be recreated with those value in it when the script ends. All the various code to unset session variables, destroy sessions, and unset the session cookie is wasted processing time and wasted bandwidth. The simplest code, which is also the most reliable way of logging someone out, is to just have a logged in/logged out column in your user table in your database and just set the value to the logged out state. Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674747 Share on other sites More sharing options...
kenshintomoe225 Posted October 26, 2008 Share Posted October 26, 2008 That sounds like a great idea! Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674759 Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2008 Share Posted October 26, 2008 The following link contains some posts listing other advantages of just using a cookie/session to identify the visitor, but using value(s) stored in the user table to decide what they can do - http://www.phpfreaks.com/forums/index.php/topic,221684.0.html Short version - even if someone is logged out, you can still keep the information that identifies who they are. And what if the session holds a language setting, do you want a multi-language web site to change to a default language just because someone logs out and you have unset/destroyed the session? Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674765 Share on other sites More sharing options...
techker Posted October 26, 2008 Author Share Posted October 26, 2008 thx guys i will study this. Quote Link to comment https://forums.phpfreaks.com/topic/130115-logout/#findComment-674980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.