• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

How to avoid PHP message Cannot send session cache limiter - headers already sent

Hi Experts !

Do you know what is needed to avoid this message ?

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/espiriplug/www/add_previo2.php:5) in /home/espiriplug/www/add_previo2.php on line 15

 
<HTML>
<HEAD>
<TITLE>Espirirplug - Recursos informatizados para a Comunidade Espírita - sem custos</TITLE>
<META NAME="Keywords" CONTENT="espiriplug, recursos informatizados, comunidade Espírita, livraria Espírita, livro Espírita, gestão de livrarias Espíritas, feira do livro Espírita, semana Espírita, gestão financeira da instituição Espírita, allan kardec, chico xavier, andré luiz">
<META NAME="Description" CONTENT="Fórum - Sustentabilidade e melhores práticas - Gestão de livraria Espírita - gestão financeira da instituição Espírita -gestão de pessoas na instituição Espírita - Feira do livro Espírita">
<meta name="robots" content="index,follow" />
<META NAME="Author" CONTENT="efuerte@uol.com.br">
</HEAD>
</HTML>


<?php

// CADASTRO PREVIO AOS DOWNLOADS
session_start();

//require('header.php');
require('config.php');
require('badwords.inc.php');

if ($_SESSION['username']) {

	$errors = array();
	$cond = TRUE;

	//Verifica apenas quando houve edição
	if ($_SESSION['ed_nome'] == TRUE)
	{
		//Verifica apenas quando houve edição
		$_SESSION['nome']    = $_POST['nome'];

	
		if($_REQUEST["nome"] == "") 
		{
			$errors[] = "<FONT COLOR='RED'> Informar o nome</FONT>";
			$cond = FALSE;
		}
	}
	
	if($_REQUEST["instit"] == "") {
		$errors[] = "<FONT COLOR='RED'> Informar Instituição</FONT>";
		$cond = FALSE;
	}

	if($_REQUEST["endereco"] == "") {
		$errors[] = "<FONT COLOR='RED'> Informar Endereço</FONT>";
		$cond = FALSE;
	}


	if($_REQUEST["cep"] == "") {
		$errors[] = "<FONT COLOR='RED'> Informar CEP</FONT>";
		$cond = FALSE;
	}

	if($_REQUEST["cidade"] == "") {
		$errors[] = "<FONT COLOR='RED'> Informar Cidade</FONT>";
		$cond = FALSE;
	}

	if($_REQUEST["uf"] == "") {
		$errors[] = "<FONT COLOR='RED'> Informar UF</FONT>";
		$cond = FALSE;
	}
	
	
	if(!$_REQUEST["focos"]){ 			
		$errors[] = "<FONT COLOR='RED'> Informar principal(is) foco(s) da instiyioção </FONT>";
		$cond = FALSE;
	}	

       
       	if(!$_REQUEST["conheceu"]){
		$errors[] = "<FONT COLOR='RED'> Informar como conheceu o site</FONT>";
		$cond = FALSE;
	}	

       	if(!$_REQUEST["conheceu"])
	{
		
		$errors[] = "<FONT COLOR='RED'> Informar como conheceu o site</FONT>";
		$cond = FALSE;
	}	
	else
	{
		foreach($_REQUEST["conheceu"] as $ch)
		{
		$ch =  substr($ch,0,2);
		
		if($ch=="00")
		{
			$errors[] = "<FONT COLOR='RED'> Indefinido Informar como conheceu o site</FONT>";
			$cond = FALSE;
		}	
		
		}

	}	
		

	/*
	if(!$_REQUEST["razao"]){	
		$errors[] = "<FONT COLOR='RED'> Informar razão para buscar o site </FONT>";
		$cond = FALSE;
	}	
       */


       	if(!$_REQUEST["razao"])
	{
		
		$errors[] = "<FONT COLOR='RED'> Informar razao que o levou a buscar o site</FONT>";
		$cond = FALSE;
	}	
	else
	{
		foreach($_REQUEST["razao"] as $ch)
		{
		$ch =  substr($ch,0,2);
		
		if($ch=="00")
		{
			$errors[] = "<FONT COLOR='RED'> Indefinido Informar razao que o levou a buscar o site</FONT>";
			$cond = FALSE;
		}	
		}
		
	}

	
	if(!$_REQUEST["products"]){
		$errors[] = "<FONT COLOR='RED'> Informar sistema(s) desejado(s)</FONT>";
		$cond = FALSE;
	}

	
	$_SESSION['cond'] = $cond;
	
	if ($cond == FALSE)
	{
		
                // preserva os dados para não perder digitação correta
		// Obrigatórios
		
		$_SESSION['nome']    = $_POST['nome'];
		$_SESSION['instit']  =$_POST['instit'];
		$_SESSION['endereco']=$_POST['endereco'];
		$_SESSION['cidade']  =$_POST['cidade'];
		$_SESSION['cep']     =$_POST['cep'];
		$_SESSION['uf']     =$_POST['uf'];

		$_SESSION['focos']     =$_POST['focos'];
		$_SESSION['conheceu']  =$_POST['conheceu'];
		$_SESSION['products']  =$_POST['products'];
		
		//Não obrigatórios
		$_SESSION['cargo']     =$_POST['cargo'];
		$_SESSION['razao']     =$_POST['razao'];
		
		display_errors();
		?>		
		<BR>
		<A HREF="previo2.php">Voltar</A>
		<?php
		
	}
	else
	{
	
	
	// Connect to server and select database.
	mysql_connect("$host", "$usermysql", "$passmysql")or die("cannot connect"); 
	mysql_select_db("$db_name")or die("cannot select DB");

	// Fetch user info
	$tbl_name="forum_user"; // Table name
	$username = $_SESSION['username'];
	$u = "SELECT * from $tbl_name WHERE username='$username'";
	$result = mysql_query($u);
	$u_info = mysql_fetch_array($result);

	// Identificação do usuário
	$id_user = $u_info['id']; 

	
	// get data that sent from form 

	$datetime=date("d/m/y h:i:s"); //create date time

	// get values that sent from form 
	$nome=$_POST['nome'];
	$instit=$_POST['instit'];
	$endereco=$_POST['endereco'];
	$cargo=$_POST['cargo'];
	$cidade=$_POST['cidade'];
	$cep=$_POST['cep'];
	$uf=$_POST['uf'];
	
	
	foreach($_REQUEST["focos"] as $fc){
		$fcc =  $fcc.substr($fc,0,2)."|";
	}

	foreach($_REQUEST["conheceu"] as $ch){
		$ch =  substr($ch,0,2);
	}
	
	foreach($_REQUEST["razao"] as $rz){
		$rz =  substr($rz,0,2);
 	}
       
	foreach($_REQUEST["products"] as $pd){
		$pdd =  $pdd.substr($pd,0,2)."|";
	}	
       
	// VERIFICA TRATAR-SE DE INCLUSÃO OU ALTERAÇÃO 
	
	$tbl_name="cad_previo"; // Table name	
	$sql = "SELECT * FROM $tbl_name WHERE id_user = '$id_user'";
	
	
	$result = mysql_query($sql);
	
	$rows2   = mysql_fetch_array($result);
	
	if($rows2){	

		$sql="UPDATE $tbl_name SET instit   = '$instit',
 		        cargo    = '$cargo', 
			endereco = '$endereco', 
			cep      = '$cep' ,
			cidade   = '$cidade', 
			uf       = '$uf',
			focos    = '$fcc',
			conheceu = '$ch',
			razao    = '$rz',
			products = '$pdd'
			WHERE    id_user = '$id_user'";
			
		$errors[] = "<FONT COLOR='BLUE'> Cadastro prévio alterado</FONT>";	
			
	//}
	}
	else 
	{
	
		//echo "INSERT.....";
		
		//echo "id_user  ".$id_user."     "."<BR>";
		//echo "rz ".$rz."     "."<BR>";

		
		$sql="INSERT INTO $tbl_name(id, id_user, nome, instit, cargo, endereco, cep, cidade, uf, focos, conheceu, razao, products)
		VALUES('$id', '$id_user', '$nome', '$instit', '$cargo', '$endereco', '$cep', '$cidade','$uf',  '$fcc', '$ch', '$rz', '$pdd')";

		//echo "sql=> ".$sql;
		
		
		$errors[] = "<FONT COLOR='BLUE'> Cadastro prévio efetuado</FONT>";
		
	}	

	
	//echo "SQL=> ".$sql;

	$result=mysql_query($sql);
	
        if($result){
		display_errors();
		?>
				
		<BR>
		<A HREF="previo2.php">Voltar</A>
		
		<?php
		}
	
	}
} else {

	echo "Voce deve estar logado para fazer o cadastro prévio !";
}

?>

<!--?php require('footer.php'); ?-->

<?php
function display_errors()
{
    global $errors;
    foreach ($errors as $err){
        echo $err, "<BR>";
    }
}
?>
<BR>
<BR>

<!--INPUT TYPE="SUBMIT" VALUE="Voltar" onClick="javascript:void(window.close())"-->

Open in new window


Even the message appears it performs correctly

Thanks in advance !
0
Eduardo Fuerte
Asked:
Eduardo Fuerte
  • 2
1 Solution
 
Cornelia YoderArtistCommented:
It most often means that you have a blank line at the top of a php script.
0
 
Cornelia YoderArtistCommented:
The other usual cause is if you output some text, for example with an echo statement, in a script that has html after that.  Any output that comes before the <HTML statements can cause this.

In your posted script, move the </HTML> to the end of the script and see if that fixes it.
0
 
Dave BaldwinFixer of ProblemsCommented:
Actually it is Not performing correctly because you are not setting a cookie with the session_id.  And that is because session_start() must come before Any output in your page or script like below.
<?php
// CADASTRO PREVIO AOS DOWNLOADS
session_start();
?>
<HTML>
...

Open in new window

0
 
Ray PaseurCommented:
In the HTTP protocol all headers must come before, and be complete, before any browser output can occur (even invisible whitespace).  A cookie is one of the HTTP headers.  This is why DaveBaldwin correctly advises you to put the PHP script before the HTML strings.

But enormously conspicuous by its absence is the function shown here.  Please learn about it before hackers destroy your data base!
http://php.net/manual/en/function.mysql-real-escape-string.php
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now