return message to user

Asked

Viewed 83 times

1

How can I change the message from "Log in" to "Welcome, User X". On the index.html page.

in index. html is like this

<p class="login"><b><a href="login.php">Faça o seu login!</a></b></p>

after the typed data is passed to the validator

<form class="form-signin" method="POST" action="valida.php">

and validates this if the login is successful :

if(isset($resultado)){
            $_SESSION['usuarioId'] = $resultado['id'];
            $_SESSION['usuarioNome'] = $resultado['nome'];
            //$_SESSION['usuarioNiveisAcessoId'] = $resultado['niveis_acesso_id'];
            $_SESSION['usuarioEmail'] = $resultado['email'];
                        if($_SESSION['usuarioId'] == $resultado['id']){
                header("Location: index.php");
            }

1 answer

2


Initially your index should be . php to be able to make the change I will give as an example. In index you put an if to check if there is a Session if it exists it shows a div otherwise shows the login. Example:

index php.

if (isset($_SESSION['usuarioNome'])) {
   echo '<p class="exemplo"><b><a href="">Bem Vindo, Usuário '.$_SESSION['usuarioNome'].'</a></b></p>';
}
else{
   echo '<p class="login"><b><a href="login.php">Faça o seu login!</a></b></p>';
}
  • still could not display the welcome messages just back to index, saved as index.php and put the code:

  • <?php if (isset($_SESSION['usuarioNome'])) { echo '<p class="example"><b><a href="">Welcome, User '.$_SESSION['usuarioNome']. '</a></b></p>'; } Else{ echo '<p class="login"><b><a href="login.php">Log in! </a></b></p>'; } ?>

  • already has session_start() in your project?

  • I will not test now with session_start();

  • puts it before the following line-> $_SESSION['userId'] = $result['id'];

  • Thank you very much. I tested it here, first log in, then it appears the name of the user I logged only. God bless you for the help!

  • You’re welcome. Kindly mark the answer as you accept.

  • 1

    It is noteworthy that the session_start(); should be before any output of php to the browser (usually at the first of the file just after the tag <?php) to avoid error Headers already sent

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.