D
D
DmitryNnov2019-04-01 00:29:09
PHP
DmitryNnov, 2019-04-01 00:29:09

Why is data not saved to the global Session variable?

Hi all. Faced with a stupid problem! The data is not saved to the global Session variable. And from one specific page. From all other pages it saves normally.
Code per 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'])){
    	//авторизируемся
    	//Проверяем на соответстиве в БД
    	$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 "Такого пользователя не существует!";    
    } else {
      echo "Такой пользователь существует!<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 "Не верный пароль!"; 
      }
      }
    }
    ?>

Trying to open on another page any of $_SESSION['test4'] or $_SESSION['logged_user'], NULL values.
Thank you for your attention. Broke my whole head.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anitspam, 2019-04-01
@anitspam

you can check this situation
https://www.php.net/session_start
Note: To use cookie-based sessions, the session_start() function must be called before rendering anything to the browser.
Output to the browser can, for example, BOM, if the file is encoded in UTF-8.

C
coderisimo, 2019-04-01
@coderisimo

And if so ?
if (!isset($_SESSION)) { session_start(); }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question