1
I have a login page that takes a variable from another file, which at the beginning is empty, and puts below the login screen. If the user misses login/password or does not enter anything, the variable must 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 login button of the form, the information goes by post to the file Login.php
:
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 archive LoginStatus.php
:
$loginStatus = "";
function setStatus($input){
$loginStatus = $input;
}
However, it is 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.!
Actually I want that if the user misses the login or leaves blank, when redirecting back to the login page be changed the variable, showing "Invalid login" below.
– Frost
This is what the script does
– Alan Rezende
Okay, it worked. Thank you so much :D
– Frost