What does this error mean?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

What does this error mean?

Post 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?
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post 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]
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post 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!');
	  }}
   }}
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

I just posted it above your post lol :P
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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();
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

thats because i removed to blank lines but that wouldnt cause an error surely?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post 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
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post 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!');
	  }}
   }}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

this wouldn't happen to be an included file inside another file??
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do you see the space just before the opening PHP tag? Remove that.
Post Reply