zhshero Posted November 16, 2010 Share Posted November 16, 2010 is it possible to update data in mysql when a user clicks logout? Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/ Share on other sites More sharing options...
JD* Posted November 16, 2010 Share Posted November 16, 2010 Sure. You can do it like any other operation, just add in your code right before you remove their session/cookie/whatever you use to track the login. Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/#findComment-1134844 Share on other sites More sharing options...
zhshero Posted November 16, 2010 Author Share Posted November 16, 2010 so i should be adding it here? function logout () { //session must be started before anything session_start (); //if we have a valid session if ( $_SESSION['logged_in'] == TRUE ) { //unset the sessions (all of them - array given) unset ( $_SESSION ); //destroy what's left session_destroy (); } //It is safest to set the cookies with a date that has already expired. if ( isset ( $_COOKIE['cookie_id'] ) && isset ( $_COOKIE['authenticate'] ) ) { /** * uncomment the following line if you wish to remove all cookies * (don't forget to comment ore delete the following 2 lines if you decide to use clear_cookies) */ //clear_cookies (); setcookie ( "cookie_id", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH ); setcookie ( "authenticate", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH ); } //redirect the user to the default "logout" page header ( "Location: " . REDIRECT_ON_LOGOUT ); } or in logout.php ? Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/#findComment-1134856 Share on other sites More sharing options...
doddsey_65 Posted November 16, 2010 Share Posted November 16, 2010 function logout () { //session must be started before anything session_start (); //if we have a valid session if ( $_SESSION['logged_in'] == TRUE ) { //unset the sessions (all of them - array given) unset ( $_SESSION ); //destroy what's left session_destroy (); } //It is safest to set the cookies with a date that has already expired. if ( isset ( $_COOKIE['cookie_id'] ) && isset ( $_COOKIE['authenticate'] ) ) { /** * uncomment the following line if you wish to remove all cookies * (don't forget to comment ore delete the following 2 lines if you decide to use clear_cookies) */ //clear_cookies (); setcookie ( "cookie_id", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH ); setcookie ( "authenticate", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH ); } //========================================================= //ADD YOUR QUERY HERE BEFORE THEY ARE REDIRECTED TO YOUR LOGOUT PAGE. //========================================================= //redirect the user to the default "logout" page header ( "Location: " . REDIRECT_ON_LOGOUT ); } Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/#findComment-1134857 Share on other sites More sharing options...
zhshero Posted November 16, 2010 Author Share Posted November 16, 2010 i added this there and all it did was set all users to 0 mysql_query("UPDATE `users` SET statusB='25A' AND user_id"); Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/#findComment-1134860 Share on other sites More sharing options...
bob2006 Posted November 16, 2010 Share Posted November 16, 2010 One Problem i see is that you query has no WHERE in it mysql_query("UPDATE users SET statusB='25A' WHERE user_id='some number'")or die(mysql_error()); i with out seeing the whole code there not much else i can tell you Quote Link to comment https://forums.phpfreaks.com/topic/218808-updating-mysql-on-logout/#findComment-1134906 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.