Login and password system without database is not allowing access

Asked

Viewed 656 times

1

When the script below is tested does not give a return that the login or password are invalid. However I understand the code is correct. Whatever is happening?

<?php
    session_start();    

    //O campo usuário e senha preenchido entra no if para validar
    if((isset($_POST['email'])) && (isset($_POST['senha']))){
        $usuario = mysqli_real_escape_string($conn, $_POST['email']); //Escapar de caracteres especiais, como aspas, prevenindo SQL injection
        $senha = mysqli_real_escape_string($conn, $_POST['senha']);
        //$senha = md5($senha);


        if (($senha == "123")  &&  ($usuario == "[email protected]" )){
        header("Location: administrativo.php");

        }else{  
            //Váriavel global recebendo a mensagem de erro
            $_SESSION['loginErro'] = "Usuário ou senha Inválido";
            header("Location: index.php");
        }
    //O campo usuário e senha não preenchido entra no else e redireciona o usuário para a página de login
    }else{
        $_SESSION['loginErro'] = "Usuário ou senha inválido";
        header("Location: index.php");
    }
?>
  • Not return means what? should write a message on the screen (via session in index.php)?

  • 1

    If you are "no database" (in the question title!) you need to remove the mysqli_real_escape_string, thus $senha = $_POST['senha'] and $usuario = $_POST['email']. The mysqli_real_escape_string requires connection to the database, if it does not have it will not be possible to use it.

No answers

Browser other questions tagged

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