C
C
codenaki2018-03-11 14:28:10
PHP
codenaki, 2018-03-11 14:28:10

How to work with Session correctly?

Question about session_abort() function ..
Why can I access data in session array after calling this method?
5aa51230cc442764883535.png

print_r($_SESSION);

echo '<br>';
echo session_start();

try {
    if(Login::getInstance()->logger($_POST)){
     echo $_SESSION['email'] = $_POST['email'].' Logged in!';
    }
}catch (LoginFailed $login){
    session_abort();
   echo $login->getMessage();
}catch (ValidationError $error){
    session_abort();
    $errors = $error->getErrors();
    foreach ($errors as $key => $value){
        if (is_array($value)){
            foreach ($value as $inner_value){
                echo '<br>';
                echo 'Valid email example => '.$inner_value;
            }
            return;
        }
        echo $error->getMessage().strtoupper($key).' => '.$value;
    }
}catch (DatabaseConnectionError $error){
    session_abort();
    echo $error->getMessage();
}

echo '<br>';
print_r($_SESSION);
echo '<br>';
var_dump(session_status()== PHP_SESSION_ACTIVE);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-11
@sidni

echo '<br>';
echo session_start();

what are these structures?
as far as remembering, it is desirable to always put the first command simply
session_start();
and before it there should be no conclusions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question