+ 2

Destroy session in php

I have two websites on localhost with login system. If I have logged into both website and set session of login let's say for website1 session is ssn1 and for website 2 session is ssn2. If I have write in log out code of website one as follow <?php session_start(); unset('ssn1'); session_destroye(); ?> Is it destroying session of website 2 i.e. ssn2?

10th Jun 2019, 2:33 PM
Shubham Tandale
Shubham Tandale - avatar
1 Respuesta
+ 2
It sounds like you have only 1 session because it sounds like both websites are under your "localhost" host name. Your example of a variable being set within the session makes things more confusing. "ssn1" reads like it is short for "session 1" even though it is just a session variable. If I'm wrong and you have 2 host names, that will be 2 independent sessions so unset and session_destroy will have no affect on the other. Regarding your code snippet, you have some other mistakes. Here are some suggestions to make it more like you really want. unset($_SESSION['ssn1']); // You can't unset a string but you can unset a key within the $_SESSION super global variable. session_destroy(); // Fixed typo in the trailing 'e' that you had
12th Jun 2019, 1:32 AM
Josh Greig
Josh Greig - avatar