Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Mateus Cruz

Erro: Cannot send session cache limiter - headers already sent

Recommended Posts

Galera, seguinte...

Estou com esse erro apresentando:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/fate1980/public_html/fate13/adm/login.php:1) in/home/fate1980/public_html/fate13/adm/login.php on line 37

 

No meu servidor local não tenho este erro, porém na hospedagem ele vem... Alguém pode me ajudar?

 

Segue o código abaixo..

<?php require_once('Connections/conexao.php'); 
?>
<?php if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['usuario'])) {
  $_SESSION["user"] = $_POST['usuario'];
  $loginUsername=$_POST['usuario'];
  $password=$_POST['senha'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "index.php?user_id=$loginUsername";
  $MM_redirectLoginFailed = "erro.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conexao, $conexao);
  
  $LoginRS__query=sprintf("SELECT nome, senha FROM usuario WHERE nome=%s AND senha=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $conexao) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link href="css/estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div style="width:300px;margin:auto;margin-top:15%">
	<form ACTION="<?php echo $loginFormAction; ?>" id="formulario" name="formulario" method="POST">
		Usuário</br>
		<input type="text" name="usuario" id="usuario" class="input"></br></br>
		Senha</br>
		<input type="password" name="senha" id="senha" class="input"></br></br>
		<button type="submit" id="botao" style="margin-left:5px;">Entrar</button></td>
	</form>
</div>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

session_start() e header() devem estar antes de qualquer saída ao navegador

Veja http://rberaldo.com.br/as-mensagens-de-erros-mais-comuns-do-php/#header

 

No seu servidor local não aparece pois você deve ter desabilitado a exibição de erros. Habilite todas as exibições de erro, como mostrado neste tópico, na Orientação No. 2, e verá o mesmo erro que aparece no servidor remoto

 

 

 

PS: funções mysql_* estão obsoletas desde o PHP 5.5 e já foram removidas no PHP 7. Prefira usar MySQLi ou PDO. Veja mais aqui: http://rberaldo.com.br/mysql-obsoleto-php/

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.