PHP Login does not load page

Asked

Viewed 698 times

1

My login system works fine on the machine, but not on the server. For on the valida.php page, which takes the form information and checks the BD for information.

login.php - Login Form

<?php
session_start();
?>

<form method="POST" action="valida.php">
        <h2>Área Restrita</h2>
  <label>Login</label>
        <input name="email_cli" type="email" autofocus required placeholder="Email" maxlength="55">
  <label>Senha</label>
        <input type="password" name="senha_cli" placeholder="Senha (seu CPF)" required><br>
        <button type="submit" class="botao_cadastro">Acessar</button>
  </form>
    <p>
        <?php if(isset($_SESSION['loginErro'])){
            echo $_SESSION['loginErro'];
            unset($_SESSION['loginErro']);
        }?>
    </p>
    <p>
        <?php 
        if(isset($_SESSION['logindeslogado'])){
            echo $_SESSION['logindeslogado'];
            unset($_SESSION['logindeslogado']);
        }
        ?>
    </p>

valida.php - Page that validates the data and redirects

<?php
session_start(); 
    //Incluindo a conexão com banco de dados   
include_once("conexao.php");    
//O campo usuário e senha preenchido entra no if para validar
if((isset($_POST['email_cli'])) && (isset($_POST['senha_cli']))){
    $usuario = mysqli_real_escape_string($conn, $_POST['email_cli']); //Escapar de caracteres especiais, como aspas, prevenindo SQL injection
    $senha = mysqli_real_escape_string($conn, $_POST['senha_cli']);
    $senha = md5($senha);

    //Buscar na tabela usuario o usuário que corresponde com os dados digitado no formulário
    $result_usuario = "SELECT * FROM clientes WHERE email_cli = '$usuario' && senha_cli = '$senha' LIMIT 1";
    $resultado_usuario = mysqli_query($conn, $result_usuario);
    $resultado = mysqli_fetch_assoc($resultado_usuario);

    //Encontrado um usuario na tabela usuário com os mesmos dados digitado no formulário
    if(isset($resultado)){
        $_SESSION['usuarioId'] = $resultado['id_cli'];
        $_SESSION['usuarioNome'] = $resultado['nome_cli'];
        $_SESSION['usuarioNiveisAcessoId'] = $resultado['nivel'];
        $_SESSION['usuarioEmail'] = $resultado['email_cli'];
        if($_SESSION['usuarioNiveisAcessoId'] == "2"){
            header("Location: video_aulas_profissional.php");
        }elseif($_SESSION['usuarioNiveisAcessoId'] == "1"){
            header("Location: video_aulas_basicos.php");
        }else{
            header("Location: login.php");
        }
    //Não foi encontrado um usuario na tabela usuário com os mesmos dados digitado no formulário
    //redireciona o usuario para a página de login
    }else{    
        //Váriavel global recebendo a mensagem de erro
        $_SESSION['loginErro'] = "Usuário ou senha Inválido";
        header("Location: login.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: login.php");
}
?>

php connection. - Connects to the BD

    <?php
$servidor = "localhost";
$usuario = "turkish";
$senha = "123456";
$dbname = "usuarios";

//Criar a conexao
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);

if(!$conn){
    die("Falha na conexao: " . mysqli_connect_error());
}else{
    //echo "Conexao realizada com sucesso";
}

?>
  • Any error messages? You updated the conexao.php for the server data?

  • No error and I changed yes.

  • Is the page shown, or is it white? Or what happens? Give details. If possible, see if an error message appears in the browser console

  • For on the page validates.php and turns white. No error appears in the console.

  • The pages: video_aulas_professional.php and video_aulas_basicos.php, where do you have to redirect after logging in, have been uploaded to the server? Their path is right?

2 answers

1

The code is capable of this to have difficulties in this line, because the variable was definite, but it has a value **.

if(isset($resultado)){

It should be something like

if($resultado!=null){

It is also possible that the server is bugging in.php login with the variables of SESSION

0

I don’t know what comic book system you’re using, but I’m sure:

$result_usuario = "SELECT * FROM clientes WHERE email_cli = '$usuario' && senha_cli = '$senha' LIMIT 1";


$result_usuario = "SELECT * FROM clientes WHERE email_cli = '$usuario' AND senha_cli = '$senha' LIMIT 1";

This could be the problem since you probably don’t have the error logging appear in PHP enabled, it might be "popping" in the query so the page appears white instead of giving the error.

  • João. I enabled the error logs but nothing appears. Nor on the console. I switched email_cli = '$user' && password_cli = '$password for email_cli = '$usuario' AND password_cli = '$password and it didn’t work either.

Browser other questions tagged

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