PHP, when relogging resends the data

0

I have a PHP form that passes the data by POST method to the same page (since the action is the default).

When a user enters a data incorrectly, for example, his password, this is registered in the database, the problem is when he refresh the page (Reload current page control + r in firefox). (That does not F5, that recharges it in an 'entire' way.)

Well, when I reload the page in this way, the entered data is re-entered.

I imagine that it is because in the url internally the data is passing such that: Página.php?User="Yoquesé"&password="Ejemplo"

then when relogging the page returns to send that data. How can I clean that 'url' once the data has been sent?

It occurs to me to pass the data by variables and not by $ _POST and once sent leave the empty variables, but is there any other alternative?

I edit with the code, as you said:

Login.php With their respective forms, and so on.

  <?php

  include 'Sharkiquerys/SharkiQuerys.php';
  $Query = new SharkiQuerys();

  if(isset($_POST['user']) && strlen($_POST['user'])>0 &&
  isset($_POST['password']) && strlen($_POST['password'])>0){

    $Query->Iniciar_sesion($_POST['user'], $_POST['password']);
  }

  ?>

And here would be the Start session method of the class that I rode.

<?php
  /*________________________________________
        MÉTODO INICIAR SESIÓN
  ________________________________________*/
  public function Iniciar_sesion($usuario, $password){

    if(password_verify($password, $this->Consulta("SELECT PASSWORD FROM registro WHERE USER =:usuario", array(':usuario' => $usuario))->fetchColumn())){

      session_start();
      $_SESSION['user'] = $this->Consulta("SELECT USER FROM registro WHERE USER = :usuario", array(':usuario' => $usuario))->fetchColumn();

      # Si los datos introducidos son correctos.
      header('Location:Desafios.php');
      # Si la contraseña es incorrecta.
    }else{ $this->Alerta('Contraseña y/o usuario incorrecto.', 'red');}
  }
?>
    
asked by Omar 07.05.2018 в 23:44
source

1 answer

0

It seems that the values of $_POST still carry the variables in this case you can return an empty matrix.

public function Iniciar_sesion($usuario, $password){

 $query = $this->Consulta("SELECT PASSWORD FROM registro WHERE USER =:usuario", array(':usuario' => $usuario))->fetchColumn();
 if(password_verify($password, $query)){

   session_start();
   $_SESSION['user'] = $this->Consulta("SELECT USER FROM registro WHERE USER = :usuario", array(':usuario' => $usuario))->fetchColumn();

   # Si los datos introducidos son correctos.
   header('Location:Desafios.php');
   # Si la contraseña es incorrecta.
 }else{ 
   // Aqui tienes que devolver $_POST vacios $_POST[] = array();
   $usuario = "";
   $password = "";
   $_POST = array();

   $this->Alerta('Contraseña y/o usuario incorrecto.', 'red');
 }
}

I have not tried this code

    
answered by 08.05.2018 в 02:50