0

I have this code to change session name:

 session_name(md5('seg'.$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']));

and this to logout:

session_name(md5('seg'.$_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']));
session_start();

$user = $_SESSION["user"];

unset($_SESSION['id']);
unset($_SESSION['user']);

session_destroy();

the problem is that sometimes it works, in first time. sometimes I need to click to logout about 3 times. What may cause this?

Gabriela Dias
  • 349
  • 2
  • 12
  • This might help: http://stackoverflow.com/questions/6472123/why-session-destroy-not-working – n-dru Apr 01 '15 at 07:28

1 Answers1

0

Try to set whole session to empty array:

session_start();
$_SESSION = array();
session_destroy();

// $_SESSION is still accessible till page change.
Justinas
  • 41,402
  • 5
  • 66
  • 96