0

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
user1400604
  • 71
  • 2
  • 12

1 Answers1

2

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

Ibrahim Azhar Armar
  • 25,288
  • 35
  • 131
  • 207