I made a check for authorization, and if the user is logged in, then write "Welcome, ***", "You have .... game coins" (because I am doing a game project). But after transferring data using the POST method, the fields do not disappear anywhere, and the greeting appears immediately under the block with the fields. Tell me how to do it instead of the authorization block, a block with a greeting and similar information. Here is the whole code:

<?php if(!isset($_SESSION['name'])) { echo '<left> <form method="post" action="index.php">
<div class="form"> <center> <li align="center">Вход</li> <img src="img/user.png" width="20" height="20"> <div class="user"> <input type="text" name="e_login" required style="width:90px; border-radius:5px; vertical-align:middle;"><br> </div> <div class="img1"> <img src="img/key.png"> <div class="key"> <input type="password" name="e_password" required style="width:90px; border-radius:5px; vertical-align:middle;"><br> <div class="input"> <input type="submit" name="enter" value="OK" style="margin-left: 0px;"> <a href=""><li style="font-size: 15px;">Забыл пароль</li></a> </div>'; } if(isset($_POST['e_login']) and isset($_POST['e_password'])){ $_SESSION['name'] = $e_login; echo '<div style="width:150px; hieght:500px;margin-top:0px;padding:0px;"> <left> <li>Добро пожаловать,</li>'; echo $_SESSION['name']; //здесь такой стремный код, ибо иначе не выводит имя пользователя echo ' </left> <center> <li>Ваши данные</li> </center> <left> <li>игровых монет:</li> <li>алмазов:</li> </left> </div>'; } ?>

    1 answer 1

    You need to postpone the check for the presence of POST parameters if(isset($_POST['e_login'])... before checking for the session variable if(!isset($_SESSION['name']))

    • I would say that it is somehow not correct to check if there are variables in the post and immediately write to the session so you can log in under any user. - Naumov
    • Well, he doesn’t have anyhow any validity checks for the sent data anywhere. - Rubikoid