Why not stores data in the global Session variable?

Hi all. Faced with a stupid problem! Data is not stored in the global Session variable. And it is with one particular page. All other pages keeps fine.

The code on the page
<?php

session_start();
 include ('includs/db.php');
$_SESSION['test4']='Hello!';
var_dump($_SESSION['test4']);
 echo $_SESSION['test4'];
 $data = $_POST;
 if (isset($data['do_login'])){
//log
 //Check sootvetstvie in the database
 $login = $data['login'];
 $password = $data['password'];
 echo $password;
 $result = mysqli_query($connection,"SELECT `login`,`password` FROM `users` WHERE `login` = '$login'");
 $r_1 = mysqli_fetch_assoc($result); 
var_dump($r_1);

 if ($r_1 == NULL){
 echo "that user does not exist!"; 
 } else {
 echo "This user exists!<br>";
 $_SESSION['logged_user'] = $login;
 if (password_verify($password, $r_1['password'])){
 echo '<script type="text/javascript">'; 
 echo 'window.location.href="http://testgamelife.ru/lk.php";'; 
 echo '</script>'; 
 } else {
 echo "Not a valid password!"; 
}
}
}
 ?>


Try to open another page on any of the $_SESSION['test4'] or $_SESSION['logged_user'], NULL values.

Thank you for your attention. All head broke.
March 19th 20 at 09:28
2 answers
March 19th 20 at 09:30
you can check this situation

https://www.php.net/session_start
Note: To use sessions based on a cookie, the function session_start() must be called before you output anything to the browser.

Is displayed in the browser, for example, a BOM if the file is in UTF-8.
March 19th 20 at 09:32
And if so ?

if (!isset($_SESSION)) { session_start(); }
Put, did not help(
And on the page where I set some variables, they are displayed. And the other isn't. - savion commented on March 19th 20 at 09:35
@savion,
and tried to insert it
if (!isset($_SESSION)) { session_start(); }

also on those pages where the session is empty ? - Melba_Bergnaum commented on March 19th 20 at 09:38
@Melba_Bergnaum, tried. Do not go out. - savion commented on March 19th 20 at 09:41
@Melba_Bergnaum, and on those pages where "empty" variables with "no problem" pages are displayed. - savion commented on March 19th 20 at 09:44
@savion,
Hmm... the reason is still there ))) .
Then there is the decision "in a forehead". It's stupid, but it helps.
Create a new empty file. Start session. Check it out. Everything is OK? Add a piece of code to check it out. Add some more. Etc. At some point everything will stop working (or not ) and you will understand what it is. Something simple is stopping the normal operation of the script. - Melba_Bergnaum commented on March 19th 20 at 09:47
@Melba_Bergnaum, today I wanted to do =)
Will accomplish your goal. But I think the solution is simple and blunt. - savion commented on March 19th 20 at 09:50
It's some kind of curse. I already deleted everything!

The first file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php

session_start();

 $_SESSION['test4']='Hello from index!';
var_dump($_SESSION['test4']);
var_dump($_SESSION['test3']);
 echo $_SESSION['test4'];


?>
the <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title</title>
 <link href="css/style.css" rel="stylesheet" type="text/css" />
 <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&amp;subset=cyrillic" rel="stylesheet"> 
</head>

the <body>

</body>
</html>


The second file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
session_start();
var_dump($_SESSION['test4']);
var_dump($_SESSION['test1']);
$_SESSION['test2']='This is a message from test1';
$_SESSION['test3']='This is a message from test1';
?>

<html>
the <head>
 <link rel="stylesheet" type="text/css" href="sss/style.css">
</head>
the <body>
 <a href="index.php">Link</a>
</body>
</html>


On the second page is not shown, the variable test4. And at first it shows test2 - savion commented on March 19th 20 at 09:53
@savioncan make
<?php
session_start();
 $_SESSION['test4']='Hello from index!';
var_dump($_SESSION['test4']);
var_dump($_SESSION['test3']);
 echo $_SESSION['test4'];
 ?>


at the top of the file. To make the code started at the top and without any spaces before them - Melba_Bergnaum commented on March 19th 20 at 09:56
And it can be associated with the server somehow? Because that does not help - savion commented on March 19th 20 at 09:59
@savion, ie, some page server like, but last.... pisses him off? )))
And he was like .. "uhhhh not! in session here will not work!" ))))
Everything has an explanation. When you realize, you'd be surprised. - Melba_Bergnaum commented on March 19th 20 at 10:02
@savion, could you solve this problem? I am willing to give access and to pay for a solution. - savion commented on March 19th 20 at 10:05
@savion, today drink beer. you can watch tomorrow. Of course, for free. Just curious to understand. Write on e-mail. - Melba_Bergnaum commented on March 19th 20 at 10:08
Wrote!) - savion commented on March 19th 20 at 10:11
5ca32ce36e05e654961107.jpeg

heed. - Melba_Bergnaum commented on March 19th 20 at 10:14

Find more questions by tags SessionsPHP