-3

This could be the sequel of this question: PHP Sessions across sub domains

I have a successful multi-domain session simply using this:

session_set_cookie_params(0, '/', '.domain.com');
session_start();

This code is working perfectly and if I visit domain.com or subdomain.domain.com I see the SESSION vars without problems and everything is working :)

The problem is when I try to logout from domain.com. I have tried everything for logout, even all this, as suggested in PHP session_destroy() manual:

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!

if (ini_get("session.use_cookies")) {
  $params = session_get_cookie_params();
  setcookie(session_name(), '', time() - 42000,
    $params["path"], $params["domain"],
    $params["secure"], $params["httponly"]
  );
}

1) session.use_cookies is ON, and setup correctly in the server 2) That code kills the session in the main domain, but not in subdomain.domain.com 3) $params shows correct information:

Array
(
    [lifetime] => 0
    [path] => /
    [domain] => .domain.com
    [secure] => 
    [httponly] => 
)

But it's not working. The session is still alive when I visit subdomain.domain.com.

Any help please ! :)

Thank you!

Community
  • 1
  • 1
FlamingMoe
  • 2,709
  • 5
  • 39
  • 64
  • Maybe it's not working in all browsers ? I'm trying with Chrome and Firefox – FlamingMoe Jan 27 '11 at 00:12
  • 1
    You asked this exact question before - don't duplicate it: [PHP sessions destroy across sub domains](http://stackoverflow.com/questions/4771690/php-sessions-destroy-across-sub-domains) – Gareth Jan 27 '11 at 00:19
  • Gareth, there's more information here, and I didn't get an answer there ... understand my frustration – FlamingMoe Jan 27 '11 at 11:21
  • 1
    @user311188: It's against the rules to post duplicates, especially of your own questions. If your question is not clear enough for people to answer properly, edit it instead of creating a new one. Editing a question will also bump it to the top of the recently asked questions list. – netcoder Jan 27 '11 at 15:05

1 Answers1

3

Simple use session_destroy() to destroy the session.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636