PHP Error Message After Login

Asked

Viewed 76 times

1

I need your help trying to solve a little problem. I have a login page and after clicking SIGN IN goes to another page validalogin.php validate the login.

Whenever the user fails the login the user is forwarded to the index.php with the end of URL index.php?login=erro2.

I want to place whenever the user has login=erro2 in the URL I put an error message.

   <?php if(header == 'erro2'){ ?>

        <div class="text-danger">
           Utilizador ou senha inválidos
         </div>        

   <?php } ?>

Something like that. It’s possible?

Thank you!

1 answer

1


In your case you will need to work with the $_GET[] for example:

   <?php if($_GET['login'] == 'erro2'){ ?>

        <div class="text-danger">
           Utilizador ou senha inválidos
         </div>        

   <?php } ?>

But taking advantage of your question there are other ways to work with this, for example with the $_SESSION[] then see to use the URL you can pass this information transparently.

For example, in the redirect of an invalid login. you set the $_SESSION['erro'] and on the page of index.php you call this Septssion instead of $_GET['login'] and then it cleans its value, it will have the same result, but without the url and case the user of a F5 on the page will not always appear error.

Test there and see if it works.

Browser other questions tagged

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