I
I
Ivan Lapshin2018-10-21 17:44:12
PHP
Ivan Lapshin, 2018-10-21 17:44:12

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.
5bcc9050670b8075015128.png5bcc905f97cd0549136108.png

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

1 answer(s)
A
Alex Murfy, 2019-07-19
@qxcoder

session_start() Lost anywhere?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question