Login system with error

Asked

Viewed 243 times

0

I have a login system, which already works on another site and I’m trying to transfer to another, and it doesn’t work at all. I would like someone to take a look. If I type in a wrong user, it returns an invalid user error, so you are checking the database. When I enter a right user, the following error messages appear:

Warning: session_start(): Cannot send Session cookie - headers already sent by (output Started at /home/netosale/public_html/e-educacao/validacao.php:2) in /home/netosale/public_html/e-educacao/validacao.php on line 28

Warning: session_start(): Cannot send Session cache Limiter - headers already sent (output Started at /home/netosale/public_html/e-educacao/validacao.php:2) in /home/netosale/public_html/e-educacao/validacao.php on line 28

Warning: Cannot Modify header information - headers already sent by (output Started at /home/netosale/public_html/e-educacao/validacao.php:2) in /home/netosale/public_html/e-educacao/validacao.php on line 36

I go there on these two lines, and I can’t locate anything abnormal. That could be happening. I’ve downloaded several other login systems, and they all fail. Is it a good problem bootstrap or something? Follow code so they can 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;


?>
  • 1

    Duplicate of https://answall.com/q/4251/5878

1 answer

0

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

Erase that:

// 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

  • Good morning Samuel. Fiz isso, mas continua dando o erro abaixo: Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/netosale/public_html/e-educacao/validacao.php:2) in /home/netosale/public_html/e-educacao/validacao.php on line 3&#xA;&#xA;Warning: Cannot modify header information - headers already sent by (output started at /home/netosale/public_html/e-educacao/validacao.php:2) in /home/netosale/public_html/e-educacao/validacao.php on line 36

  • Edit your question by placing the contents of all these files.

Browser other questions tagged

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