Destroying Null Session Variables

I have created session for my website.To have session started i have wrote following code on each link of website:

session_start();
if(isset($_SESSION['User']))
{
  //session_start();
  $sesvar = $_REQUEST['sid'];
} 
else
{
  $sesvar = " ";
}

But when I click log out button session get destroyed.But value of sid(ie parameter to set session variable is set to null.)To destroy session i wrote following code:

if(isset($_REQUEST['out']))
{
    session_start();
    session_unset();
    //unset($_SESSION['User']);
    session_destroy();
    header("Location:login.html");
    exit;   
}

After logout as i get sid=null and after that if i click any link of website the welcome msg is still there with null session variable.Please help.

Answers


you are actually not using session variable to store the session data.

i assume in below code you are trying to use session variable to store some value

$sesvar = $_REQUEST['sid'];

you are doing it wrong way, to store any session data you need to store it in super global $_SESSION array. so for example.

$_SESSION['var'] = $_REQUEST['sid'];

and to check or fetch the value you need to check the value in $_SESSION


Need Your Help

FstCGI: How to clear the out stream?

fastcgi clear outputstream

I have the code to write a headers to the fastcgi outstream. In case the write body fails, I want to attempt to write new headers indicating the failure mode without the original headers being sent...

Attempted to divide by zero in SSRS Chart

reporting-services ssrs-2008 ssrs-2008-r2 reportingservices-2005 ssrs-2012

This is a Pie Chart report. I have searched but still cannot resolve this issue with the message: