0

Everything I found about this error message is saying that either there's no session started or I have no rights, unfortunately neither of those is the case.

My session is active and by the time I try to destroy it in my logout method I get

warning: session_destroy(): session object destruction failed

My symptoms seem to be quite like the ones in this question which, sadly, has no answers. Also when I try to log out a couple of times it destroys the session successfully. Sometimes it takes 2 logouts some times 5 it's never the same amount, but it also never destroys it from the first attempt. I find this really awkward, can someone give me some advice?

Community
  • 1
  • 1
php_nub_qq
  • 15,199
  • 21
  • 74
  • 144
  • 1
    @alfasin come on, are you serious? Did you even read the question. I clearly stated that none of the solutions given in http://stackoverflow.com/questions/8549757/why-session-object-destruction-failed are valid in my case – php_nub_qq Sep 21 '13 at 20:19
  • have you tried to unset the sessions first? normally session_destroy should work, but you can always try to unset first – jonas vermeulen Sep 21 '13 at 20:19
  • @jonasvermeulen what is strange is that I have this system for more than half a year now and it just started giving me this crap without me changing anything. Unsetting isn't really an option because apart from it not being quite a good solution, I also need not to have any error messages by rules :( – php_nub_qq Sep 21 '13 at 20:20
  • @jonasvermeulen Also, just tried out unsetting first and it doesn't do it either `O.o`. EDIT: Actually it does, but I had to refresh manually.. Which is a result of the error from session_destroy() which I must avoid absolutely mandatory – php_nub_qq Sep 21 '13 at 20:23
  • @php_nub_qq, strange indeed, maybe just try to restart your server or something. will clear the cache of your php sessions. if that doesn't help i don't know any other solutions myself – jonas vermeulen Sep 21 '13 at 20:25
  • @php_nub_qq saying "everything you found" doesn't really provide a good indication of what you tried and what you didn't try. It would be better if you provide more details in regards in your question. Does the save-handler configured to use files ? if so, what the session path ? how do you know that a session actually exists at the time of the logout - did you echo something from the session during logout ? – Nir Alfasi Sep 21 '13 at 20:34
  • @jonasvermeulen restarted my whole system actually, and yet there it is again `:(` – php_nub_qq Sep 21 '13 at 20:36
  • @alfasin I know that the session exists because the user remains logged in everything in the session array is kept. – php_nub_qq Sep 21 '13 at 20:37

2 Answers2

0

Try this soluation:

<?php 

session_start(); 
$_SESSION = array(); 

if (isset($_COOKIE[session_name()])) { 
   setcookie(session_name(), '', time()-42000, '/'); 
} 
session_destroy(); 
?>
Osama Jetawe
  • 2,697
  • 6
  • 24
  • 40
0

I just found out what the problem was, and it seems extremely weird and illogical.

My Logout button is an anchor tag, and I was playing around with my site testing stuff and I started tapping tab to see what elements I can focus on in an ordinary page. I noticed that all buttons from the menu lane can be focused except the logout button and that was due to a missing href attribute, so I added an empty href attribute just so that it can be focused by tabbing. Apparently an empty href tag redirects to the root ( I guess that is due to the <base> tag I use ). So every time I clicked the logout button I was being redirected to the main page ( I didn't notice this at first because I was actually on that page, lol right ), which apparently gets in the way of destroying the session from the ajax request that was sent by clicking the very same button. My assumption would be that php had failed destroying the session object because it was in use, loading the page I have redirected myself to, and sometimes the logout worked, because the redirect was slow and the ajax call executed in time before php had started creating the new page.

I have removed the href attribute and everything works now.. I would like to ask you to comment whether I'm right or wrong and possibly give the correct answer, thanks!

php_nub_qq
  • 15,199
  • 21
  • 74
  • 144
  • I think that my problem might have been an process which accessed the sesion-file and which crashed. Or maybe my filesystem was corrupt ... but I never had this problem again, so I guess your problem was different – maja Sep 24 '13 at 08:30
  • just had the same problem. tried to logout and had set a href attribute. deleting the attribute solved the problem. – oshell Feb 06 '15 at 20:14