How to send an error message to the user in the correct way?

0
Hello, I am a student of PHP and would like to know more about you the following, if you send the error message to the user through $_SESSION and after this message has been " the session being destroyed, would be a good practice. and if not, in what ways can I do this?

My Example:

Login Simulation:

 else{
    //2.1- se der erro no passo anterior mostrar o erro
    //criar uma sessão para mandar a mensagem na index
    $_SESSION['erro'] ='Preencha os campos Corretamente!';
    header('location:index.php');
    }

Now this is the page that receives the message:

<?php 
if (isset($_SESSION['erro'])) {
  echo "<div class='card-panel yellow darken-4'>".$_SESSION['erro']."</div>";
  session_destroy();
}?>
    
asked by anonymous 18.04.2018 / 15:33

0 answers