My test code is as follows:

Asked

Viewed 39 times

-1

<?
    session_start();
    $nome = filter_input(INPUT_POST, 'nome');
    $_SESSION['nome'] = $nome;  

  ?>
  <form action="teste.php" method="post">

    <input type="text" name="nome"> <br> <br>
    <button>Enviar</button>
  </form>

<?php
  session_start();

  if($_SESSION['nome'] == 'sim' ) {
    echo 'Logado'; // Ele não entra aqui
  } else {
    header('location: index.php?login=erro'); // Ele so fica na pagina index, independente do valor passado no input
  }

Now if I do so it logs, but it logs the user independent of the value passed in the input

session_start();

  if($_SESSION['nome'] != 'sim' ) {
    echo 'Logado'; //Ele entra aqui
  } else {
    header('location: index.php?login=erro');
  }
  • Yes my logic would be this, but any value I type including the yes it enters the login.

1 answer

1


session_start();

  if($_SESSION['nome'] != 'sim' ) {
    header('location: index.php?login=erro');
  } else {
    echo 'Logado'; //Ele entra aqui;
  }

N the IF syntax o == It is to compare if the value is equal and qunado this as != shows that it is different, ie, would be an Else within the comparison.... the correct is to reverse.

Browser other questions tagged

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