Answer the question
In order to leave comments, you need to log in
I create session (for registration). In the authorization file, the array with sessions exists and works, but in the main file, the $_SESSION array is empty. What's wrong?
Here is the code for the authorization file:
<?php session_start(); require "phpStart.php" ?>
<?php
if(isset($_POST['doLogin'])){
$data=$_POST;
$errors=array();
$user=R::findOne('users','login=?',array($data['login']));
if($user){
if(password_verify($data['password'],$user->password)){
$_SESSION['logged_user']=$user;
echo '<div style="color:green">'.'Здравствуйте '.$_SESSION['logged_user']->login.', вы авторизованны.</div><form action="/"><button>Назад</button></form>';
print_r($_SESSION['logged_user']);
}else{
echo '<div class="errors er2" style="color:red">Вы ввели не правильный пароль!</div>';
}
}else{
echo '<div class="errors er2" style="color:red">Пользователь не найден!</div>';
}
}
?>
<form action="/log.php" method="POST">
<input type="text" placeholder="Логин" name="login" value="<?php echo $_POST['login']; ?>">
<input type="password" placeholder="Пароль" name="password" value="<?php echo $_POST['password']; ?>">
<button name="doLogin">Войти</button>
</form>
<?php
session_start();
require "phpStart.php";
?>
<?php print_r($_SESSION); if(isset($_SESSION['logged_user'])){ ?>
test
else{
}<a href="reg.php">Регистрация</a>
<a href="log.php">Войти</a>
} Answer the question
In order to leave comments, you need to log in
session_start();
In the main block, drag to the second block.
you start 2 different sessions.
from the docks:
The session_start() function creates a session, or resumes an existing one, based on a session ID passed in a GET or POST request, or passed in a cookie.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question