Warning: Cannot modify header information - headers already

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
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Warning: Cannot modify header information - headers already

Post by kendall »

Hello, i have the following lines of code in my code

Code: Select all

line: 24 <?php require_once('connection.php'); ?>
<?php

// some code to excute and if sucessful

line 107 header(sprintf("Location: %s", $location));
exit;
this is more or less the flow of ALL my php scripts yet this is the ONLY Page that gives this problems

the exact error is
Warning: Cannot modify header information - headers already sent by (output started at modify_references.php:24) in modify_references.php on line 107
the lines in question are what has been posted and i dont now WTF is the problem

the reason why i say
this is more or less the flow of ALL my php scripts yet this is the ONLY Page that gives this problems
is because the php scripts were built using dreamweaver php builder extensions and this is the pattern for ALL the scripts...ALL only different is the the input information and the database action..

wat...oh wat is driving me CARZY
:cry:

Kendall
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post by trollll »

In the source, what lines do you have before the line 107? If you have anything printed out it will yell at you just like that. Drove me crazy until I realized that I had output some HTML tags before that line. Once the header gets sent, it won't let you modify it.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

trolll,

exactly....ah mean i know this so it was the first thing i was looking for...the php process doesn;t need to print anything so i thought it was a mistake i made....but i dont see it... the only thing it probably does is define some new variable

Code: Select all

$editFormAction = $HTTP_SERVER_VARS&#1111;'PHP_SELF'];
if (isset($HTTP_SERVER_VARS&#1111;'QUERY_STRING'])) 
  $editFormAction .= "?" . $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];

if ((isset($HTTP_POST_VARS&#1111;"MM_update"])) && ($HTTP_POST_VARS&#1111;"MM_update"] == "form1")) &#123;
	$errStr = false;
	if (phpversion() > "4.0.6") &#123;
		$HTTP_POST_FILES = &$_FILES;
	&#125;
	define("MAX_SIZE",30000);
	define("DESTINATION_FOLDER", "../images/references_images");
	$_accepted_extensions_ = "jpeg,jpg";
	if(strlen($_accepted_extensions_) > 0)&#123;
		$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
	&#125; else &#123;
		$_accepted_extensions_ = array();
	&#125;
	$_file_ = $HTTP_POST_FILES&#1111;'IMG'];
	if(is_uploaded_file($_file_&#1111;'tmp_name']) && $HTTP_POST_FILES&#1111;'IMG']&#1111;'error'] == 0)&#123;
		$_name_ = $_file_&#1111;'name'];
		$_type_ = $_file_&#1111;'type'];
		$_tmp_name_ = $_file_&#1111;'tmp_name'];
		$_size_ = $_file_&#1111;'size'];
		if($_size_ > MAX_SIZE && MAX_SIZE > 0)
			$errStr = "File Size should NOT exceed 30000Bytes (30KB)";
			
		$_ext_ = explode(".", $_name_);
		$_ext_ = strtolower($_ext_&#1111;count($_ext_)-1]);
		if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0)
			$errStr = "Invalid Extension. Please Upload only JPEG('.jpg') extension FILES!!!";
		
		if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER))
			$errStr = "Could not Upload File. Please check the directory";
			
		if($errStr == false)&#123;
			if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_))
				$Image = $_name_;
			else $errStr = 'Could not Upload File. Please try again';
		&#125;
	&#125;
	if($errStr == false)&#123;
  		$updateSQL = sprintf("UPDATE references_table SET Company=%s, Image=%s, Description=%s, Category=%s WHERE `REF`=%s",
         GetSQLValueString($HTTP_POST_VARS&#1111;'Company'], "text"),
         GetSQLValueString(isset($Image) ? $Image : "NULL", "text"),
         GetSQLValueString($HTTP_POST_VARS&#1111;'Description'], "text"),
         GetSQLValueString($HTTP_POST_VARS&#1111;'Category'], "int"),
         GetSQLValueString($HTTP_POST_VARS&#1111;'REF'], "int"));

  		mysql_select_db($database_Resco_Products, $Resco_Products);
  		$Result1 = mysql_query($updateSQL, $Resco_Products) or die(mysql_error());
		$Status = 'Reference REF# -'.$HTTP_POST_VARS&#1111;'REF'].' updated!';
 		$updateGoTo = "list_reference.php?Status=".urlencode($Status);
 		if (isset($HTTP_SERVER_VARS&#1111;'QUERY_STRING'])) &#123;
   			$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    		$updateGoTo .= $HTTP_SERVER_VARS&#1111;'QUERY_STRING'];
 		&#125;
 		header(sprintf("Location: %s", $updateGoTo));
		exit;
	&#125;
now as i said with the above code....im using it as is in a next script give or take a few variable....and it works. can you detect anything here

Kendall
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post by trollll »

Hmmm... Nothing really jumps out at me. You may want to make some variables at different points through the script and initialize them all with headers_set() and the print them all out at the end of the script to narrow it down to a certain section of code. Then you can narrow it down from there to the actual line using the same method.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

you might want to read: this thread
it was stickied for a reason. if you still need help, then search for "echo" in your code. find the line of the first occurance.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

can you show us the whole of the code on that page?

Mark
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

m3rajk
Master,


AAAAAAAAAAAAAAAHHHHHH....the spaces....the spaces...the spacesss......I had put spaces to separate the code as i was going to comment it however i forgot to put the comments....thanks
Post Reply