Page 1 of 1

What does this error mean?

Posted: Fri Aug 03, 2007 3:54 pm
by SirChick
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\registercode.php:2) in C:\xampp\htdocs\registercode.php on line 13


Line 13 is:

session_start();


does it mean i have not ended the session or something?

Posted: Fri Aug 03, 2007 3:57 pm
by guitarlvr
session_start() MUST be before anything you output in your page. If you output anything to the browser, even a blank space, you will get those errors.[/b]

Posted: Fri Aug 03, 2007 4:03 pm
by SirChick
I don't though! I have a php echo on line 4 but even when removed the same thing error appeared.

This is what i got, on line 11 is the session start. The only physical output to the browser is the echo mysql_error();.
But when removed i get the same error anyway... am i missing something?

Code: Select all

<?php

if(!mysql_connect("localhost", "root", "private")){
echo mysql_error();
exit;
}
else{
	mysql_select_db("civilian") or die (mysql_error());
	if (isset($_POST['RegistrationSubmission'])){
	session_start();

   
   $Captcha = ($S_SESSION['security_code']);
   $UserCaptcha = mysql_real_escape_string($_POST['security_code']);
   if($Captcha == $UserCaptcha){
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
	  $Username = mysql_real_escape_string($_POST['Username']); 
		$Password = mysql_real_escape_string($_POST['Password']); 
		$Password2 = mysql_real_escape_string($_POST['Password2']);
		$Email = mysql_real_escape_string($_POST['EmailRegistration']);
		$Country = mysql_real_escape_string($_POST['CountryChoice']);
		$ip = $_SERVER["REMOTE_ADDR"];
		$Gender = $_POST['Gender'];
		$TermsOfService = $_POST['TermsOfService'];
		$jump2 = 1;
	  if ($Password != $Password2) {
			echo "Passwords did not match";
				if ($TermsOfService == "off") {
				
					die('You must agree to the terms of service before registering! Please press back and try again!');
					$jump2 = 0;
				}
			}
			if ($jump2 ==1){
				$chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'");
				$getUSERNAME = mysql_fetch_assoc($chkUSERNAME);
				 if($_POST['Username'] == $getUSERNAME['Username']) {
					  die('Username already registered, please choose a different username! That has not already been taken!');
				 }
				$chkEmail = mysql_query("SELECT * FROM `userregistration` WHERE `Email` = '".$_POST['EmailRegistration']."'");
				$getEmail = mysql_fetch_assoc($chkEmail);
				if($_POST['EmailRegistration'] == $getEmail['Email']) {
					  die('Email is already in use please use a different valid email address!!');
				}
			 if ($Password == $Password2) {
				$query = "INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) 
						  Values ('$Username', '$Password', '$Email', '$Country', '$ip', '$Gender')";
				mysql_query($query) or die(mysql_error());
      unset($_SESSION['security_code']);
   }}} else {
      // Insert your code for showing an error message here
	  If($Captcha != $UserCaptcha){
		//die('Your security code did not match the generated image, please try again!');
	  }}
   }}
?>

Posted: Fri Aug 03, 2007 4:11 pm
by RobertGonzalez
The server already served the page so you cannot send any more headers from where you are in the code. Look again. You only get headers sent messages if the response headers have been sent.


What is in this file: C:\xampp\htdocs\registercode.php?

Posted: Fri Aug 03, 2007 4:13 pm
by SirChick
I just posted it above your post lol :P

Posted: Fri Aug 03, 2007 4:46 pm
by RobertGonzalez
Well, if line 13 is session start, according to PHP, then you have something above it, because in this code, your session_start() call is on line 10:
  1. <?php
  2. if(!mysql_connect("localhost", "root", "private")){
  3. echo mysql_error();
  4. exit;
  5. }
  6. else{
  7. mysql_select_db("civilian") or die (mysql_error());
  8. if (isset($_POST['RegistrationSubmission'])){
  9. session_start();

Posted: Fri Aug 03, 2007 4:51 pm
by SirChick
thats because i removed to blank lines but that wouldnt cause an error surely?

Posted: Fri Aug 03, 2007 4:54 pm
by RobertGonzalez
Surely? Maybe not.

Perhaps you can run the app again and view source to see what is output before the headers are resent.

Posted: Fri Aug 03, 2007 4:55 pm
by guitarlvr
SirChick wrote:thats because i removed to blank lines but that wouldnt cause an error surely?
It could. If PHP is outputing a blank space, even one, you'll get that message

Posted: Fri Aug 03, 2007 6:01 pm
by SirChick
guitarlvr wrote:
SirChick wrote:thats because i removed to blank lines but that wouldnt cause an error surely?
It could. If PHP is outputing a blank space, even one, you'll get that message

but i have not echo'd anything so have can it be displaying the blank lines?

Posted: Fri Aug 03, 2007 6:54 pm
by RobertGonzalez
Post the entire first 50 lines of the page that is giving your this error. If there are any includes, post those too. Post it exactly as it is your editor. DO NOT TRIM IT OR LEAVE ANYTHING OUT. You may star out any DB connection details, but do not leave anything out.

Posted: Fri Aug 03, 2007 7:00 pm
by SirChick
This is exactly how it is as of right now. from line 1 to line 56.

After that it is the then the HTML for the registration form.

Code: Select all

<?php

if(!mysql_connect("localhost", "root", "private")){
echo mysql_error();
exit;
}
else{
	mysql_select_db("civilian") or die (mysql_error());
	if (isset($_POST['RegistrationSubmission'])){
	session_start();

   
   $Captcha = ($S_SESSION['security_code']);
   $UserCaptcha = mysql_real_escape_string($_POST['security_code']);
   if($Captcha == $UserCaptcha){
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
	  $Username = mysql_real_escape_string($_POST['Username']); 
		$Password = mysql_real_escape_string($_POST['Password']); 
		$Password2 = mysql_real_escape_string($_POST['Password2']);
		$Email = mysql_real_escape_string($_POST['EmailRegistration']);
		$Country = mysql_real_escape_string($_POST['CountryChoice']);
		$ip = $_SERVER["REMOTE_ADDR"];
		$Gender = $_POST['Gender'];
		$TermsOfService = $_POST['TermsOfService'];
		$jump2 = 1;
	  if ($Password != $Password2) {
			echo "Passwords did not match";
				if ($TermsOfService == "off") {
				
					die('You must agree to the terms of service before registering! Please press back and try again!');
					$jump2 = 0;
				}
			}
			if ($jump2 ==1){
				$chkUSERNAME = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '".$_POST['Username']."'");
				$getUSERNAME = mysql_fetch_assoc($chkUSERNAME);
				 if($_POST['Username'] == $getUSERNAME['Username']) {
					  die('Username already registered, please choose a different username! That has not already been taken!');
				 }
				$chkEmail = mysql_query("SELECT * FROM `userregistration` WHERE `Email` = '".$_POST['EmailRegistration']."'");
				$getEmail = mysql_fetch_assoc($chkEmail);
				if($_POST['EmailRegistration'] == $getEmail['Email']) {
					  die('Email is already in use please use a different valid email address!!');
				}
			 if ($Password == $Password2) {
				$query = "INSERT INTO `userregistration` (Username,Password,Email,Country,IP,Gender) 
						  Values ('$Username', '$Password', '$Email', '$Country', '$ip', '$Gender')";
				mysql_query($query) or die(mysql_error());
      unset($_SESSION['security_code']);
   }}} else {
      // Insert your code for showing an error message here
	  If($Captcha != $UserCaptcha){
		die('Your security code did not match the generated image, please try again!');
	  }}
   }}
?>

Posted: Sat Aug 04, 2007 12:17 am
by volka
please try

Code: Select all

<?php
function foo() {
  if ( headers_sent($file, $line) ) {
    echo "\n<br />headers sent: ", $file, '@', $line, "<br />\n";
    $c = file($file);
    for($i=$line-2; $i<$line+3; $i++) {
      echo "#$i: ", isset($c[$i]) ? trim($c[$i]):'', "<br />\n";
    }
  }
}

if(!mysql_connect("localhost", "root", "private")){
  echo mysql_error();
  exit;
}
else{
  mysql_select_db("civilian") or die (mysql_error());
  if (isset($_POST['RegistrationSubmission'])){
    foo();
    session_start();

    $Captcha = ($S_SESSION['security_code']);
 ...
and post the output.

Posted: Sat Aug 04, 2007 7:31 am
by iknownothing
this wouldn't happen to be an included file inside another file??

Posted: Sat Aug 04, 2007 9:35 pm
by RobertGonzalez
Do you see the space just before the opening PHP tag? Remove that.