Answer the question
In order to leave comments, you need to log in
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 "Не верный пароль!";
}
}
}
?>
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question