Php Error Trying To Destroy Uninitialized Session
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn
Session_destroy() Not Working
more about Stack Overflow the company Business Learn more about hiring developers or posting php session_destroy ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Session_status
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Warning: session_destroy(): Trying to destroy uninitialized session up vote 3 php check if session started down vote favorite 1 my class.inc file: used code for my logout: session_start(); require($path."include/class.inc"); if(!empty($_GET['logout'])){ $object=new logout(); $object->logout(); $content='5;url='.$path.'index.php'; } when i the logout function is called, it destroys the session. but shows the warning: Warning: session_destroy(): Trying to destroy session_start uninitialized session in class.inc on line 9 unable to troubleshoot as session is not being destroyed by any other means before the session_destroy() of class.inc. kindly help. php session share|improve this question edited Aug 12 '13 at 14:13 asked Aug 12 '13 at 13:49 RatDon 1,05021341 2 Where are you starting the session? –Tobias Kun Aug 12 '13 at 13:50 This error warning comes when there is not any session started. –Rohit Kumar Choudhary Aug 12 '13 at 13:53 i'm starting the session in each page at the top just after
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Cannot Modify Header Information - Headers Already Sent By
Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error — session_destroy() — Trying to destroy uninitialized session up vote 0 down vote favorite http://stackoverflow.com/questions/18188716/warning-session-destroy-trying-to-destroy-uninitialized-session I'm getting an error using session_destroy() in my PHP code. The following script is on every page and if a user is signed in, it checks if the session is valid or not, killing the session if it's not. session_start(); // check for users already signed in and check session if (isset($_SESSION['user_id'])) { $uid = $_SESSION['user_id']; // check user_id is a valid id if (!is_numeric($uid) || $uid < 0) { session_unset(); http://stackoverflow.com/questions/18551030/error-session-destroy-trying-to-destroy-uninitialized-session session_destroy(); session_regenerate_id(true); } // if user agent is different, kill session if ($_SESSION['user_agent'] != $_SERVER['HTTP_USER_AGENT']) { session_unset(); session_destroy(); session_regenerate_id(true); } // if user's last login record fails to match session_id, kill session $SQL = "SELECT user_session FROM users_logins "; $SQL .= "WHERE user_id = :user_id "; $SQL .= "ORDER BY time_in DESC LIMIT 1;"; $STH = $DBH_P->prepare($SQL); $STH->bindParam(':user_id', $uid); $STH->execute(); $row = $STH->fetch(); if ($STH->rowCount() > 0) { $db_sid = $row['user_session']; } if ($db_sid !== session_id()) { session_unset(); session_destroy(); session_regenerate_id(true); } } The error I receive indicates the failure is coming from the last session_destroy() call. Am I using session_destroy() correctly or not? I have read other questions on here but most answers advise that session_start() must be used before destroying it, but I have started the session at the top, before the check begins. php session share|improve this question asked Aug 31 '13 at 17:41 TheCarver 7,9761763119 Why are you using session_unset and session_destroy? regenerating the id should be enough. And why are you checking the user id in the session to be numeric? If that should be necessary at all – do it before you put it into the session. –CBroe Aug 31 '13 at 17:47 @CBroe I'm using session_unset and session_destroy to lo
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://stackoverflow.com/questions/17522574/warning-session-destroy-trying-to-destroy-uninitialized-session-with-phpcas of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign php error up Warning: session_destroy(): Trying to destroy uninitialized session with phpCas up vote 0 down vote favorite I am facing a problem today with the phpCas library https://wiki.jasig.org/display/CASC/phpCAS. Problem is the following, when I try to use some logout function, I got the message Warning: session_destroy(): Trying to destroy uninitialized session After giving a quick look into the phpCas's library code, I manage php error trying to figure out where the problem comes from, here is a snippet of a logout function : session_write_close(); header('Location: '.$cas_url); phpCAS::trace("Prepare redirect to : ".$cas_url); session_unset(); session_destroy(); The problem there it seems is that session_write_close() actually close the session then session_destroy() can't work. Tried to put the session_write_close() in comment and worked like a charm but it leads to two questions : Is the problem really coming from there? Or should it work? If the problem do really come from there, why is it there and nobody complaining? Thought phpCas was a reknown library used by many. php symfony2 cas phpcas share|improve this question asked Jul 8 '13 at 8:58 MisterJ 3331418 2 Why is the symfony2 tag in your question? Because sf2 doesn't handle the sessions like this. –Dani Sancas Jul 8 '13 at 9:04 Because I'm using symfony2 and thought the bug might be in relation (even if it seems not) –MisterJ Jul 8 '13 at 9:06 add a comment| 3 Answers 3 active oldest votes up vote 0 down vote accepted Sounds like you checked out the master branch