title: Two different PHP sessions in same domain, how to destroy only one of them?
body: <p>In the same domain I have two applications running</p>
  
  <ul>
  <li><code>localhost/app1</code></li>
  <li><code>localhost/app2</code></li>
  </ul>
  
  <p>Here is my session management:</p>
  
  <p><strong>Page for check the login:</strong></p>
  
  <pre><code>session_start();
  //...check if the login is correct
  
  //if is correct
  $_SESSION["SESSION_VALID"] = true;
  //redirect to the correct page
  
  //if is not correct
  $_SESSION["SESSION_VALID"] = false;
  //redirect to the login
  </code></pre>
  
  <p><strong>A page of my application:</strong></p>
  
  <pre><code>//check the session
  session_start();
  if(!$_SESSION['SESSION_VALID']){
      //redirect to login page
      header("Location: ../../login/");
      exit;
  }
  </code></pre>
  
  <p><strong>Logout page:</strong></p>
  
  <pre><code>session_start();
  session_unset();
  session_destroy();
  //redirect to the login
  header("Location: ../login/");
  </code></pre>
  
  <hr>
  
  <p>Now, back to the initial problem. I have already read several questions on Stack Overflow related to this problem. The solution would be to use the <code>session_name("app1")</code> before every <code>session_start()</code>.</p>
  
  <p>Ok, but now the problem is another: when I logout from one of the application, how can I set which session should be destroyed? Just call <code>session_name("app1")</code> before the destruction of the session? Is the correct solution? Something like that?</p>
  
  <pre><code>session_name("name_of_the_session_to_destroy");
  session_start();
  session_unset();
  session_destroy();
  header("Location: ../login/");
  </code></pre>