Cannot modify header information

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
thegreen
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 8:55 pm

Cannot modify header information

Post by thegreen »

Right off I will state I am relatively new to PHP so go easy.javascript:emoticon(':)')

I am trying to use header(sprintf("Location: %s", $updateGoTo)); but I keep getting Warning: Cannot modify header information - headers already sent by (output started at /pfi_site/pfiac/specials.php:62). The only other place in my page that I use header is on line 3: header ("Cache-control: private" );

Can anyone find what is about to drive me crazy???

Code: Select all

<?php
session_start();
header ("Cache-control: private" ); //IE 6 Fix
?>
<?php require_once('../../Connections/connPFI.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

mysql_select_db($database_connPFI, $connPFI);
$query_catdrilldown = "SELECT * FROM catdrilldown ORDER BY Title ASC";
$catdrilldown = mysql_query($query_catdrilldown, $connPFI) or die(mysql_error());
$row_catdrilldown = mysql_fetch_assoc($catdrilldown);
$totalRows_catdrilldown = mysql_num_rows($catdrilldown);

if ($HTTP_GET_VARS['CatID'] != ''){
   $colname_specials = "1"; // default value when CatID is blank on first entry
   if (isset($HTTP_GET_VARS['CatID'])) {
     $colname_specials = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['CatID'] : addslashes($HTTP_GET_VARS['CatID']);
   }
} else {
   $colname_specials = "999999";
}

if ($colname_specials == "1") { // determine sort order by Home Page or not
   $sort = "HomeSort"; // HomeSort when CatID is blank on first entry
} elseif ($colname_specials == "999999") {
   $sort = "HomeSort"; // when Home Page is selected
} else {
   $sort = "Sort"; // selection is not Home Page but has a CatID
}

mysql_select_db($database_connPFI, $connPFI);
$query_specials = sprintf("SELECT * FROM specials WHERE CatLink = '%s' AND IsActive = '1' and Expire > NOW() ORDER BY $sort ASC", $colname_specials);
$specials = mysql_query($query_specials, $connPFI) or die(mysql_error());
$row_specials = mysql_fetch_assoc($specials);
$totalRows_specials = mysql_num_rows($specials);

$colname_catdrilldown_label = "999999999";
if (isset($HTTP_GET_VARS['CatID'])) {
  $colname_catdrilldown_label = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['CatID'] : addslashes($HTTP_GET_VARS['CatID']);
}
mysql_select_db($database_connPFI, $connPFI);
$query_catdrilldown_label = sprintf("SELECT Title FROM catdrilldown WHERE CatID = %s", $colname_catdrilldown_label);
$catdrilldown_label = mysql_query($query_catdrilldown_label, $connPFI) or die(mysql_error());
$row_catdrilldown_label = mysql_fetch_assoc($catdrilldown_label);
$totalRows_catdrilldown_label = mysql_num_rows($catdrilldown_label);

$i = 1; //initialize counter

$MM_paramName = ""; 

// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
// create the list of parameters which should not be maintained
$MM_removeList = "&index=";
if ($MM_paramName != "") $MM_removeList .= "&".strtolower($MM_paramName)."=";
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";
// add the URL parameters to the MM_keepURL string
reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) {
	$nextItem = "&".strtolower($key)."=";
	if (!stristr($MM_removeList, $nextItem)) {
		$MM_keepURL .= "&".$key."=".urlencode($val);
	}
}
// add the URL parameters to the MM_keepURL string
if(isset($HTTP_POST_VARS)){
	reset ($HTTP_POST_VARS);
	while (list ($key, $val) = each ($HTTP_POST_VARS)) {
		$nextItem = "&".strtolower($key)."=";
		if (!stristr($MM_removeList, $nextItem)) {
			$MM_keepForm .= "&".$key."=".urlencode($val);
		}
	}
}
// create the Form + URL string and remove the initial '&' from each of the strings
$MM_keepBoth = $MM_keepURL."&".$MM_keepForm;
if (strlen($MM_keepBoth) > 0) $MM_keepBoth = substr($MM_keepBoth, 1);
if (strlen($MM_keepURL) > 0)  $MM_keepURL = substr($MM_keepURL, 1);
if (strlen($MM_keepForm) > 0) $MM_keepForm = substr($MM_keepForm, 1);
?>
<?php echo "<?xml version="1.0" encoding="iso-8859-1"?".">"; ?>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

well... first off use that handy php tag. the site admins arebig on.

secondly, you have a lot of <?php ?> tags. ddon't close php unless you need to


third, why do i get the feeling the files starts "<html>.....<?php...." ?

fourth.. start the file <?php

then have everything that does sends nothing to the user.
then send your headers. then start the html/php interaction
thegreen
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 8:55 pm

Post by thegreen »

їquote="m3rajk"]well... first off use that handy php tag. the site admins arebig on.ї/quote]
їphp]Sorry.ї/php] New to the forum. None of those cute little buttons work in my browser anyway.

їquote="m3rajk"]secondly, you have a lot of <?php ?> tags. ddon't close php unless you need toї/quote]
OK. I removed all the extra tags and I still get the warning.

їquote="m3rajk"]third, why do i get the feeling the files starts "<html>.....<?php...." ?ї/quote]
I have no idea why you get that feeling. What I posted is the first 106 lines in the page. Line 107 is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN". Then line 108 start the html with: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

їquote="m3rajk"]fourth.. start the file <?phpї/quote]
It already starts that way.

їquote="m3rajk"]then have everything that does sends nothing to the user.
then send your headers. then start the html/php interactionї/quote]
???????????? Comments 1-4 have nothing to do with the problem. This one I plain just don't understand what you are trying to say.
?>
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Headers are special bits of text before a page is loaded that tell the browser special stuff. You have to send all the headers, and THEN you can output via echo() or print(). If you absolutely need to have the text echoed to the screen before you set a header, consider output buffering.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Also, try and avoid using DreamWeaver to generate PHP code since it tends to put in a fair bit of pointless code.

Mac
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

I was wondering about that...
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

їquote="thegreen"]їquote="m3rajk"]well... first off use that handy php tag. the site admins arebig on.ї/quote]їphp]Sorry.ї/php] New to the forum. None of those cute little buttons work in my browser anyway.ї/quote]then you should turn on javascript. then the buttons will add the tagsїquote]їquote="m3rajk"]secondly, you have a lot of <?php ?> tags. ddon't close php unless you need toї/quote]OK. I removed all the extra tags and I still get the warning.ї/quote]ok. didn't think it would just looks messy and like you're giving us diced up code to look at andwe're missing somethingїquote]їquote="m3rajk"]third, why do i get the feeling the files starts "<html>.....<?php...." ?ї/quote]I have no idea why you get that feeling. What I posted is the first 106 lines in the page. Line 107 is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN". Then line 108 start the html with: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">ї/quote]i hope my last response explained that. hmm.. double check that there is nothing before the first <?php that your editor is hidingїquote]їquote="m3rajk"]fourth.. start the file <?phpї/quote]It already starts that way.ї/quote]like i said, make sure your editor isn't fooling you with something hidden or that it's inserting on save.їquote]їquote="m3rajk"]then have everything that does sends nothing to the user.
then send your headers. then start the html/php interactionї/quote]
???????????? Comments 1-4 have nothing to do with the problem. This one I plain just don't understand what you are trying to say.
?>[/quote]what i meant is that if it doesn't send something to the user.. ie: you're not echoing the variable..then make sure it's in the first php block. this way when you're ready to toss out things like the headers, you know that everything has been prepared. i'm not entirely positive on this, but some lanuages act on things as they see them, therefore having the work after the print out will have the print out always look wrong.
thegreen
Forum Newbie
Posts: 3
Joined: Fri Jun 27, 2003 8:55 pm

Post by thegreen »

Thanks twigletmac.

Output buffering was the key!
Post Reply