0
<?php
// conexão
require_once'connect.php';
// Sessão
session_start();
if(isset($_POST["usuario"])){
$erros = array();
$usuario = mysqli_escape_string($connect,$_POST["usuario"]);
$senha = mysqli_escape_string($connect,$_POST["senha"]);
if(empty($usuario) or empty($senha)){
$erros[] = "<li> O campo Usuário/Senha precisa ser preenchido ! </li>";
}else{
$sql = "SELECT login FROM usuarios WHERE login = '$usuario'";
$resultado = mysqli_query($connect, $sql);
if(mysqli_num_rows($resultado) > 0){
$senha = md5($senha);
$sql = "SELECT * FROM usuarios WHERE login = '$usuario' AND senha = '$senha'";
$resultado = mysqli_query($connect, $sql);
if(mysqli_num_rows($resultado) == 1){
$dados = mysqli_fetch_array($resultado);
mysqli_close($connect);
$_SESSION['logado'] = TRUE;
$_SESSION['id_usuario'] = $dados['id'];
**header('Location: home.php');**
}else{
$erros[] = "<li> Usuário ou senha não conferem.</li>";
}
}else{
$erros[] = "<li> Usuário não cadastrado.</li>";
}
}
}
?>
Login System
</header>
<main>
<form action=<?php echo $_SERVER['PHP_SELF']; ?> method="POST">
<h2> Login </h2>
<input type="text" name="usuario" placeholder="Usuário">
<input type="password" name="senha" placeholder="Senha">
<input type="submit" value="Login">
<?php
if( !empty($erros) ) {
?>
<p> <?php foreach($erros as $erro){
echo $erro;
} ?></p>
<?php
}
?>
</form>
</main>
<footer>
</footer>
</body>
**Everything is working, but it does not redirect to the home page.php, I do not know what can be. I appreciate the help. **
home.php files and the file that has the access conditions are in the same folder hierarchy? I made an example of the test.php file accessing home.php being that home.php is in a folder and the test.php file is outside the folder. 'header( 'Location: .. /testefolder/home.php' );'
– Eduardo
except for those asterisks I don’t see why it doesn’t work.
– user60252
Nothing related to the error, which in my view does not exist in the code. Only one way to save processing. The way the code is, obligatorily, if the user exists, will perform 2 SELECTS. Well, if the user exists, we will soon at last. Now if login and password do not return, do the other SELECT with login to check if it exists, if it exists inform that password does not check and otherwise inform that User not registered. See suggestion at https://anotepad.com/notes/njdb3w
– user60252