Check for completed session

3

I'm having trouble checking for something inside the session. The functions I am using are:    Function to check if someone is logged in

if(usuarioestalogado()){?>
<p class="alert-success">Você está logado como: <?= usuariologado() ?></p>
else...

Auxiliary Functions

 session_start();
function logausuario($email){
  $_SESSION["usuario_logado"] = $email;
}
function usuarioestalogado()
{
return (isset($_SESSION["usuario_logado"]));
 }

While he never enters if just else and looking at cookies at session, the:

Does anyone have any idea why this occurs?

    
asked by anonymous 27.01.2015 / 18:21

1 answer

3

If I'm not mistaken in comparisons, PHP considers Null to be False. One of the alternatives is to do the following:

function usuarioestalogado()
{
return isset($_SESSION["usuario_logado"])) && !empty($_SESSION["usuario_logado"])  ? true : false;
 }
    
28.01.2015 / 11:37