Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting session variable even after session destroy

I am newbie in php. I can not under stand a thing that session variable is outputting even after session_destroy() and session_unset().Here is my simple code for test

`session_start();
 SESSION['name']='sovon';
 session_destroy();
 session_unset($_SESSION['name']);
 echo $_SESSION['name'];

`

The output is 'sovon'. My question what is session_destroy() and session_unset() doing here and whats the difference between them? Oh! when I am deleting session_destroy() that variable is getting unset. why?

like image 797
faisal ahmed Avatar asked Jan 28 '26 19:01

faisal ahmed


1 Answers

I got it faisal, session_distroy is destroying session if its created in other pages. If the session variable created on the same page then it will be remain. The best practice is to null the session variable after session distroY $_SESSION = NULL;

Like I am using in logout,

session_start();
session_distory();
$_SESSION = NULL;
header('Location: Login.php');

I think this help you.

like image 161
user3477550 Avatar answered Jan 31 '26 17:01

user3477550



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!