I have a login page that takes a variable from another file, which at the beginning is empty, and places it below the login screen. If the user misses login / password or does not enter anything, the variable should be changed to "Invalid Login" on a second page that will redirect back to the login screen, where the text will appear in red.
I have, in the file index.php
(login page):
<br/><p class='login-status'>
<?php
include "Controller/LoginStatus.php";
echo $loginStatus;
?>
</p>
When the user clicks on the form login button, the information goes by post to the Login.php
file:
include "../Model/Usuario.php";
$tipo = $_POST['tipo'];
$login = $_POST['login'];
$senha = $_POST['senha'];
$data = array($tipo, $login, $senha);
$error = false;
foreach($data as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if ($error) {
include "LoginStatus.php";
setStatus("Login inválido.");
header("Location: ../");
} else {
$user = new Usuario();
$retorno = $user->verificarLogin($tipo, $login, $senha);
if($retorno){
echo "Login efetuado. Redirecionando...";
header("Location: ../View");
} else{
include "LoginStatus.php";
header("Location: ../");
}
}
And in the file LoginStatus.php
:
$loginStatus = "";
function setStatus($input){
$loginStatus = $input;
}
However, you are not changing the loginStatus variable. I wanted to know what the error was, or if you have some more direct / easy method to change it from Login.php. Thank you in advance!