S
S
Sergey Miller2021-06-10 20:40:33
PHP
Sergey Miller, 2021-06-10 20:40:33

Why isn't the session working?

Hello, I encountered sessions for the first time. Help, please, to understand why the session start does not work?

if(empty($_POST['name'])){
.....
}
else{

if(isset($_SESSION["test"])){
unset($_SESSION["test"]);
session_destroy();
}
session_start();
$_SESSION["test"] = md5(time());
header('Location: /test');
}


After redirecting to the test.php page

if(isset($_SESSION["test"])){
echo 'yes';
} else{
echo 'no';
}


Output no

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-06-10
@blackseabreathe

For the session to work, it must be started on each page at the very beginning

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question