[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-02
4
Medium Priority
?
424 Views
Last Modified: 2012-05-12
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
Comment
Question by:Eduardo Fuerte
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 36900724
It most often means that you have a blank line at the top of a php script.
0
 
LVL 27

Expert Comment

by:Cornelia Yoder
ID: 36900734
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 36900862
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36900925
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question