I always keep the session in php

0

hi migos I have a login system which when it should expire because I pass it to another page that does not have session start does not expire. that is, it always keeps me full session variables and it is not what I want I leave the code. When I refresh the index page or I want to reach it through the browser, the message of the condition continues to appear, as if the session varials were full. Thanks

In the login.php file I have this:

session_start();
require_once("conexion.php");
 $contra = $_POST['contra'];
 $email = $_POST['mail'];
$consulogin = "select * from usuario
where email = '{$email}'
 and contrasena='{$contra}' ";

 $res = $lnk->query($consulogin); 
 $numeroderegistros = $res->num_rows;
 $fila = $res->fetch_object();

if($numeroderegistros==1){
        if($fila->nivel==0){
            $_SESSION['sesion']=0;

        } else {

            $_SESSION['sesion']=1;
            $_SESSION['nombre']=$fila->nick;
            header('location:index.php');

        }

} else {

    header('location:index.php');

}

And in the index.php file I have this:

if(isset($_SESSION['sesion']) && $_SESSION['sesion']==true ){
                echo "hola ".$_SESSION['nombre']." bienvenido";*/

            } else { ?>

           <form id="login" method="post" action="login.php" ><br>
        Email: <br>
  <input type="email" name="mail" ><br>
  Contraseña: <br>
  <input type="password" name="contra" autocomplete="new-password"><br>
  <input type="submit" value="Submit">
</form> 
            <?php } ?>
            </div>
    
asked by trevol 13.06.2018 в 13:00
source

1 answer

1

Let's see what you're doing, if you redirect to the index.php and do this check it's that you need to use session, because you're using $ _SESSION, in the index.php what you have to do in that IF is to identify the user and make a logout to destroy the "session_destroy ()" session and the login form appears again

        if(isset($_SESSION['sesion']) && $_SESSION['sesion']==1){
            echo "hola ".$_SESSION['nombre']." bienvenido";*/
            /* Y AQUI COMO YA TIENES SESION SIEMPRE TE ENTRARA AQUI
               A MENOS QUE HAGAS UN FORMULARIO Y QUE TE HAGA UN 
               SESSION_DESTROY();*/
        } else { ?>

       <form id="login" method="post" action="login.php" ><br>
         Email: <br>
         <input type="email" name="mail" ><br>
         Contraseña: <br>
         <input type="password" name="contra" autocomplete="new-password"> 
         <br>
         <input type="submit" value="Submit">
       </form> 
    <?php } ?>
        </div>

Do not forget to put the session_start () in the index.php because in the end you will use it!

    
answered by 13.06.2018 в 13:55