limitphp Posted January 22, 2009 Share Posted January 22, 2009 I use sessions now to handle the login. When they click logout, it takes them to website.com?logout=yes here is the code I am trying to use to log them out: <?php if ($logout=="yes")//*********** DESTROY SESSION, DELETE COOKIE, DELETE ENTRY { session_unset(); session_destroy(); if (isset($_COOKIE['nwo'])) { $queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'"; mysql_query($queryDelete) or die (mysql_error()); setcookie("loggedin","out", time()-3600*24); } } ?> It gives me a Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\wamp\www\greckle\index.php does anyone know what I am doing wrong? thanks... Link to comment https://forums.phpfreaks.com/topic/141951-solved-what-is-the-correct-way-to-get-rid-of-a-session/ Share on other sites More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 Something like... <?php session_start(); if ($logout=="yes")//*********** DESTROY SESSION, DELETE COOKIE, DELETE ENTRY { $_SESSION = array(); session_destroy(); if (isset($_COOKIE['nwo'])) { $queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'"; mysql_query($queryDelete) or die (mysql_error()); setcookie("loggedin","out", time()-3600*24); } } ?> But I still don't know where $logout comes from? Link to comment https://forums.phpfreaks.com/topic/141951-solved-what-is-the-correct-way-to-get-rid-of-a-session/#findComment-743289 Share on other sites More sharing options...
limitphp Posted January 22, 2009 Author Share Posted January 22, 2009 Something like... <?php session_start(); if ($logout=="yes")//*********** DESTROY SESSION, DELETE COOKIE, DELETE ENTRY { $_SESSION = array(); session_destroy(); if (isset($_COOKIE['nwo'])) { $queryDelete = "DELETE FROM cookie WHERE tempID = '$_COOKIE[loggedin]'"; mysql_query($queryDelete) or die (mysql_error()); setcookie("loggedin","out", time()-3600*24); } } ?> But I still don't know where $logout comes from? sorry... $logout = check_input($_GET['logout']); Link to comment https://forums.phpfreaks.com/topic/141951-solved-what-is-the-correct-way-to-get-rid-of-a-session/#findComment-743331 Share on other sites More sharing options...
limitphp Posted January 22, 2009 Author Share Posted January 22, 2009 i think i know what it was.... I forgot to put session_start(); on the page.... now it works fine with the original code. session_unset(); session_destroy(); Link to comment https://forums.phpfreaks.com/topic/141951-solved-what-is-the-correct-way-to-get-rid-of-a-session/#findComment-743334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.