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 !
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cornelia YoderArtistCommented:
It most often means that you have a blank line at the top of a php script.
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.
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.