PHP. How to return the script, a message about wrong username/password?

0 like 0 dislike
3 views
Good afternoon. There is a script login to the site. If you enter the wrong login/password input fields are reset and no messages just. I would like to write an error login password. How to specify it in the script? Thank you!
login.php
<?php$err = '';include("dbconnect.php");require_once 'auth.php';// If post, check userif (!empty($_POST['userlogin']) && !empty($_POST['pass'])) {// Verify user and passwordif (isValidUser($_POST['userlogin'], $_POST['pass'], $mysqli)) {// Log in$_SESSION['userlogin'] = $_POST['userlogin'];header('Location: index.php');exit();}else{$_SESSION['userlogin'] = FALSE;}}// The user login pageinclude 'templates/header.php';?><!--login modal-->User authentication
<?phpinclude 'templates/footer.php';</code>
by | 3 views

1 Answer

0 like 0 dislike
Can do it through our session. That is, if the data entered is not correct, you can leave a message.

For example

if (!empty($_POST['userlogin']) && !empty($_POST['pass'])) { // Verify user and password if (isValidUser($_POST['userlogin'], $_POST['pass'], $mysqli)) { // Log in $_SESSION['userlogin'] = $_POST['userlogin']; header('Location: index.php'); exit(); } else { // if not match then $_SESSION['message'] = "Username or password incorrect."; $_SESSION['userlogin'] = FALSE; } }
by

Related questions

110,608 questions
257,186 answers
0 comments
33,717 users