Pergunta

I have a very perplexing problem, namely at the top of my files I call a foreign function "sessionTest", which tests various session criteria and returns the correct header string. This is necessary, because I have two different headers: one for logged in users and one for non-users/logged out users.

My problem is in the following code:

<?php include './session.php';
  include './db.php';
  $con = genCon();
  if(isset($_SESSION['logged'])){
    echo "Logged: ".$_SESSION['logged'];    
  }
  $headerstring = sessionTest($con); ?>

 ...Rest of Page...

For some reason, isset($_SESSION['logged']) is returning false here, but true in sessionTest:

function sessionTest($con){
    session_start();
    $fingerprint = md5($_SERVER['HTTP_USER_AGENT'].session_id());

    if(isset($_SESSION['user']) && isset($_SESSION['logged']) && $_SESSION['logged']==TRUE){
        $dbFingerprint = qGetUserFingerprint($_SESSION['user'],$con);
        $fpMatch = ($dbFingerprint == $fingerprint);

        //LEAVING OUT NON RELEVANT CODE     

        $headerstring = './lheader.html';
    }else{
        $headerstring = './header.html';
    }
    return $headerstring;
}

The headerstring is being set to lheader.html, so isset($_SESSION['logged']) is returning true here. Does anyone have an idea why??

Thanks in advance!

Foi útil?

Solução

you need to put session_start();

 <?php 
   -> session_start();
     include './session.php';
      include './db.php';
      $con = genCon();
      if(isset($_SESSION['logged'])){
        echo "Logged: ".$_SESSION['logged'];    
      }
      $headerstring = sessionTest($con); ?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top