Login system with error [duplicate]

0

I have a login system, which already works on another site and I'm trying to transfer it to another, and it does not work at all. I'd like someone to take a look. If I type a wrong user, it returns an invalid user error, so it is checking the database. When I enter a certain user, the following error messages appear:

  

Warning: session_start (): Can not send session cookie - headers already   sent by (output started at   /home/netosale/public_html/e-education/validation.php:2) in   /home/netosale/public_html/e-education/validation.php on line 28

     Warning: session_start (): Can not send session cache limiter - headers   already sent (output started at   /home/netosale/public_html/e-education/validation.php:2) in   /home/netosale/public_html/e-education/validation.php on line 28

     

Warning: Can not modify header information - headers already sent by   (output started at   /home/netosale/public_html/e-education/validation.php:2) in   /home/netosale/public_html/e-education/validation.php on line 36

I go there on these two lines, and I can not locate anything abnormal at all. What could be happening. I've already downloaded several other login systems, and all of them give error. Is it a good bootstrap problem or something? Here's the code to take a look:

<?php
     // Verifica se houve POST e se o usuсrio ou a senha щ(sуo) vazio(s)
  if (!empty($_POST) AND (empty($_POST['usuario']) OR empty($_POST['senha']))) {
      header("Location: index.php"); exit;
  }
  // Tenta se conectar ao servidor MySQL
  mysql_connect('localhost', 'xzthyb45', '164544515151561') or trigger_error(mysql_error());
  // Tenta se conectar a um banco de dados MySQL
  mysql_select_db('ljklfdfjkldj') or trigger_error(mysql_error());

  $usuario = mysql_real_escape_string($_POST['usuario']);
  $senha = mysql_real_escape_string($_POST['senha']); 
  // Validaчуo do usuсrio/senha digitados
  $sql = "SELECT 'id', 'nome', 'nivel' FROM 'userPerms' WHERE ('usuario' = '".$usuario ."') AND ('senha' = '". sha1($senha) ."') AND ('ativo' = 1) LIMIT 1";
  $query = mysql_query($sql);
  if (mysql_num_rows($query) != 1) {
      // Mensagem de erro quando os dados sуo invсlidos e/ou o usuсrio nуo foi encontrado
      echo "Login invсlido!"; exit;
  } else {
     //  Salva os dados encontados na variсvel $resultado
     $resultado = mysql_fetch_assoc($query);
  }


      // Se a sessуo nуo existir, inicia uma
      if (!isset($_SESSION)) session_start();

       //Salva os dados encontrados na sessуo
      $_SESSION['UsuarioID'] = $resultado['id'];
      $_SESSION['UsuarioNome'] = $resultado['nome'];
      $_SESSION['UsuarioNivel'] = $resultado['nivel'];

       // Redireciona o visitante
      **header("Location: novaTela.php");** 
      exit;


?>
    
asked by anonymous 04.03.2018 / 15:50

1 answer

0

session_start() should always be the first thing to run in your application, if it runs after or is duplicated, that error will appear.

Delete this:

// Se a sessуo nуo existir, inicia uma
if (!isset($_SESSION)) session_start();

And put session_start (); as the first thing executed on your index.php

    
04.03.2018 / 21:29