Answer the question
In order to leave comments, you need to log in
Incomprehensible situation with the session in php?
I have a site on a local server, in the root of the directory of which there is an index.php file. Scripts are located in the php folder respectively. I implemented registration and authorization through sessions. Almost everything works correctly, the user registers in the database, then he can enter the site. The authorization script (login.php) is located in the php folder. When it is executed, the user 'user" is written to the session, and if you display $_SESSION['logged_user'] in the same script, then everything is displayed: both login and password and mail... But when the user returns to index.php, the session is null.
if( empty($errors))
{
$_SESSION['logged_user'] = $user;
echo '<div style = "color:green">'.'Вы авторизованы '.$_SESSION['logged_user'].'<a href="/index.php">Вернуться на главную</a></div>';
}
<?php
var_dump($_SESSION['logged_user']);
if(empty($_SESSION['logged_user'])){
?>
<li><a id='Enter'>войти</a></li>
<?php
}
else {
?>
<li><a href="php/logout.php" id='Exit'>выйти</a></li>
<?php
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question