ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Cannot modify header information
Posted by poe on Dec-06-2010 21:57
Attachments:
Hi Peter,

For some reason I receive this message.
Warning: Cannot modify header information - headers already sent by ...
I checked all that I can but I still don't know why this is happen.

Thanks
Mircea
2BW.php
  <?php
    
  require_once("percentile.class.php"); // ai nevoie de fisierul asta sa calculezi procentele

 //$StartDate = $_POST['start_date'];
 
$StartDate = "2010-12-02";

$Ora_Start = "000000"; #aici incepe ziua

$Ora_End = "235959";  #aici se termina aceeasi zi

$selected_An=substr($StartDate, 0, 4);

$selected_Luna=substr($StartDate, 5, 2);

$selected_Zi=substr($StartDate, 8, 2);

$displayfromtime = $selected_Zi."/".$selected_Luna."/".$selected_An."-"."00".":"."00";

                                                                                                               ////echo $displayfromtime;

// calculeaza ce zi din saptamina este ziua aleasa

$date= $selected_An."/".$selected_Luna."/".$selected_Zi; //$date = '2007/08/30' asa trebuie sa fie formatul 

//$weekday_as_text = date('l', strtotime($date)); // am nevoie cind scriu ziua in grafic 
//echo "<br>";
//echo $weekday_as_text;
$weekday_as_number = date('N', strtotime($date));
//echo "<br>";

// L M M J V S D
// 1 2 3 4 5 6 7
// Daca x este ziua din saptamina (ex 3 ptr Miercuri)
// Cite zile traba sa adaugi in dreapta sa completezi saptamina Right=7-x = 4 (4, 5, 6,7)
// Cite zile traba sa adaugi in stinga zilei alese Left = 6-Right = 6-4=2 (1,2)
// exemplu x = 3 Right=4 (joi vineri simbata duminica)  Left=6-4=2 ( luni marti)


//Cind incepe saptamina
$days_on_right_side = 7 - $weekday_as_number;
$days_on_left_side = 6 - $days_on_right_side;

/////////////////////////////////////////////////////////////////////

$number_of_day_curent_month = cal_days_in_month(CAL_GREGORIAN,$selected_Luna,$selected_An);
$day_of_week_end = $selected_Zi+$days_on_right_side;
$day_of_week_start = $selected_Zi-$days_on_left_side;

// daca luna este Ianuarie si $day_of_week_start <1 trebuie sa aleaga anul anterior
if ($selected_Luna == 01 and $day_of_week_start <1)
{ $number_of_day_previous_month = cal_days_in_month(CAL_GREGORIAN,12,$selected_An-1);
  $An_start = $selected_An-1;
 }
 elseif ($selected_Luna == 01 and $day_of_week_start >=0) // daca este ianuarie dar inceputul saptamini nu cade inafara luni si deci nici in anul precedent $An_start = $selected_An 
 {   $An_start = $selected_An; }
 
elseif ( $selected_Luna !=01) // daca luna nu este ianuarie 
{ $number_of_day_previous_month = cal_days_in_month(CAL_GREGORIAN,$selected_Luna-1,$selected_An);
  $An_start = $selected_An;
 }
// daca luna este decembrie si saptamina in care sa ales ziua trece in anul urmator $An_end= $selected_An+1
if ( $selected_Luna == 12 and $day_of_week_end > $number_of_day_curent_month)
{$An_end= $selected_An+1;}
else{
$An_end= $selected_An;
    }

// daca ziua aleasa cade intr-o saptamina care incepe intr-o luna si se termina in alata
// calculeza numarul de zile pe care o are luna anterioara luni curente si scade cite zile din saptamina sint in luna anterioara

if ( $day_of_week_start <1)

 { $Luna_start = $selected_Luna - 1; 
   $Ziua_start = $number_of_day_previous_month - abs($day_of_week_start);
 }
 else
 { $Luna_start = $selected_Luna;
   $Ziua_start = $day_of_week_start;
 }

// daca saptamina se termina in luna viitoare celei selectate 
//daca $day_of_week_end = 33 si luna are 30 de zile rezulta ca 3 zile sint in luna urmatoare

if ($day_of_week_end > $number_of_day_curent_month)

 { $Luna_end = $selected_Luna + 1; 
   $Ziua_end = $day_of_week_end - $number_of_day_curent_month;
 }
else 
 { $Luna_end = $selected_Luna; 
   $Ziua_end = $day_of_week_end;
 }

if ( $Luna_start == 0) { $Luna_start = 12;} // daca luna este ianuarie adica 1 ecpresia $Luna_start = $selected_Luna - 1 devine 0  deci luna anterioara li ianuarie este decembrie
if ( $Luna_end == 13) { $Luna_end = "01";} // daca luna este decembrie 12 +1 fac 13 deci $Luna_end va fi ianuarie ptru ca dupa decembrie vine ianuarie

if( $Ziua_end <10) { $Ziua_end = "0".$Ziua_end;}
if( $Ziua_start <10) {$Ziua_start = "0".$Ziua_start;}

if(strlen($Luna_start)<2) { $Luna_start = "0".$Luna_start;} //citeodate afiseaza 1 in loc de 01 pentru ianuarie de ex in mysql trebuie sa fie 01 nu 1
if(strlen($Luna_end)<2) { $Luna_end = "0".$Luna_end;}

$week_start = $An_start."/".$Luna_start."/".$Ziua_start; 
$week_end = $An_end."/".$Luna_end."/".$Ziua_end;

//echo "<br>";
//echo $week_start;
//echo "<br>";
//echo $week_end;
//echo "<br>";

// gaseste cind incepe si cind se termina prima zi din saptamina care este intotdeauna LUNI

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z1_start = $An_start.$Luna_start.$Ziua_start.$Ora_Start; // z1 = ziua 1 a saptamini 
$z1_end = $An_start.$Luna_start.$Ziua_start.$Ora_End;

//echo $z1_start."-".$z1_end;
//echo "<br>";


// a doua zi din saptamina

$x = cal_days_in_month(CAL_GREGORIAN,$Luna_start,$An_start);
$z1=$Ziua_start; // z1 = ziua 1 a saptamini 

//daca luna_start diferea de luna_end 

if($z1 < $x)
{$z2 = $z1 + 1 ; $luna = $Luna_start;}
else{$z2 = 1 ; $luna = $Luna_end; }
if(strlen($z2)<2) { $z2 = "0".$z2;}

////TREBUIE VAZUT DE VARIABILA $An_start IN CAZUL CIND SAPTAMINA INCEPE IN DECEMBRIE 2010  SI SE GATA IN IANUARIE 2011
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z2_start = $An_start.$luna.$z2.$Ora_Start ;
$z2_end = $An_start.$luna.$z2.$Ora_End;
//echo $z2_start."-".$z2_end;
//echo "<br>";

if($z2 < $x AND $luna = $Luna_start)
{$z3 = $z2 + 1 ; $luna = $Luna_start;}
elseif($luna = $Luna_end)
{$z3 = $z2 + 1-$x ;}
if($z3 < 7) {$luna = $Luna_end;}
if(strlen($z3)<2) { $z3 = "0".$z3;}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z3_start = $An_start.$luna.$z3.$Ora_Start ;
$z3_end = $An_start.$luna.$z3.$Ora_End;
//echo $z3_start."-".$z3_end;
//echo "<br>";



if($z3 < $x AND $luna = $Luna_start)
{$z4 = $z3 + 1 ; $luna = $Luna_start;}
elseif($luna = $Luna_end)
{$z4 = $z3 + 1-$x ;}
if($z4 < 7) {$luna = $Luna_end;}
if(strlen($z4)<2) { $z4 = "0".$z4;}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z4_start = $An_start.$luna.$z4.$Ora_Start ;
$z4_end = $An_start.$luna.$z4.$Ora_End;
//echo $z4_start."-".$z4_end;
//echo "<br>";


if($z4 < $x AND $luna = $Luna_start)
{$z5 = $z4 + 1 ; $luna = $Luna_start;}
elseif($luna = $Luna_end)
{$z5 = $z4 + 1 - $x ;}
if($z5 < 7) {$luna = $Luna_end;}
if(strlen($z5)<2) { $z5 = "0".$z5;}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z5_start = $An_start.$luna.$z5.$Ora_Start ;
$z5_end = $An_start.$luna.$z5.$Ora_End;
//echo $z5_start."-".$z5_end;
//echo "<br>";


if($z5 < $x AND $luna = $Luna_start)
{$z6 = $z5 + 1 ; $luna = $Luna_start;}
elseif($luna = $Luna_end)
{$z6 = $z5 + 1 - $x ;}
if($z6 < 7) {$luna = $Luna_end;} 
if(strlen($z6)<2) { $z6 = "0".$z6;}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z6_start = $An_start.$luna.$z6.$Ora_Start ;
$z6_end = $An_start.$luna.$z6.$Ora_End;
//echo $z6_start."-".$z6_end;
//echo "<br>";

if($z6 < $x AND $luna = $Luna_start)
{$z7 = $z6 + 1 ; $luna = $Luna_start;}
elseif($luna = $Luna_end)
{$z7 = $z6 + 1- $x ;}
if($z7 < 7) {$luna = $Luna_end;}
if(strlen($z7)<2) { $z7 = "0".$z7;} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$z7_start = $An_start.$luna.$z7.$Ora_Start ;
$z7_end = $An_start.$luna.$z7.$Ora_End;
//echo $z7_start."-".$z7_end;
//echo "<br>";
  
  
 # conectare la baza de date
 
 

$mysqli = new mysqli('localhost','root','')or die(mysql_error());
$mysqli->select_db('demosite')or die(mysql_error());
$tabel_db = "demo" ; 
  
 ###  LUNI  ##############################################################################
$datele_de_luni = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z1_start."  AND ".$z1_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_luni)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$luni_min = min($OAT);
$stat = new Stat();
$luni_25th_percentile = $stat->percentile($OAT,25);
$luni_50th_percentile = $stat->median($OAT);
$luni_75th_percentile = $stat->percentile($OAT,75);
$luni_95th_percentile = $stat->percentile($OAT,95);
$luni_max = max($OAT);
################################################################################### 

  
  
  
 ###  MARTI  ##############################################################################
$datele_de_marti = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z2_start."  AND ".$z2_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_marti)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$marti_min = min($OAT);
$stat = new Stat();
$marti_25th_percentile = $stat->percentile($OAT,25);
$marti_50th_percentile = $stat->median($OAT);
$marti_75th_percentile = $stat->percentile($OAT,75);
$marti_95th_percentile = $stat->percentile($OAT,95);
$marti_max = max($OAT);
###################################################################################   
  
###  MIERCURI  ##############################################################################
$datele_de_miercuri = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z3_start."  AND ".$z3_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_miercuri)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$miercuri_min = min($OAT);
$stat = new Stat();
$miercuri_25th_percentile = $stat->percentile($OAT,25);
$miercuri_50th_percentile = $stat->median($OAT);
$miercuri_75th_percentile = $stat->percentile($OAT,75);
$miercuri_95th_percentile = $stat->percentile($OAT,95);
$miercuri_max = max($OAT);
###################################################################################     
  
###  JOI  ##############################################################################
$datele_de_joi = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z4_start."  AND ".$z4_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_joi)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$joi_min = min($OAT);
$stat = new Stat();
$joi_25th_percentile = $stat->percentile($OAT,25);
$joi_50th_percentile = $stat->median($OAT);
$joi_75th_percentile = $stat->percentile($OAT,75);
$joi_95th_percentile = $stat->percentile($OAT,95);
$joi_max = max($OAT);
###################################################################################  
  
 ###  vineri  ##############################################################################
$datele_de_vineri = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z5_start."  AND ".$z5_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_vineri)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$vineri_min = min($OAT);
$stat = new Stat();
$vineri_25th_percentile = $stat->percentile($OAT,25);
$vineri_50th_percentile = $stat->median($OAT);
$vineri_75th_percentile = $stat->percentile($OAT,75);
$vineri_95th_percentile = $stat->percentile($OAT,95);
$vineri_max = max($OAT);
###################################################################################  
  
  ###  simbata  ##############################################################################
$datele_de_simbata = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z6_start."  AND ".$z6_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_simbata)) {	$OAT []= $row[0]; }  // temperatura de afara
//print_r ($OAT);

$simbata_min = min($OAT);
$stat = new Stat();
$simbata_25th_percentile = $stat->percentile($OAT,25);
$simbata_50th_percentile = $stat->median($OAT);
$simbata_75th_percentile = $stat->percentile($OAT,75);
$simbata_95th_percentile = $stat->percentile($OAT,95);
$simbata_max = max($OAT);
###################################################################################   
  
  
  ###  duminica  ##############################################################################
$datele_de_duminica = $mysqli->query("SELECT A4 FROM $tabel_db WHERE 
TIMPUL BETWEEN ".$z7_start."  AND ".$z7_end." Order By TIMPUL ");

while ($row = mysqli_fetch_row($datele_de_duminica)) {	$OAT []= $row[0]; }  // temperatura de afara

$duminica_min = min($OAT);
$stat = new Stat();
$duminica_25th_percentile = $stat->percentile($OAT,25);
$duminica_50th_percentile = $stat->median($OAT);
$duminica_75th_percentile = $stat->percentile($OAT,75);
$duminica_95th_percentile = $stat->percentile($OAT,95);
$duminica_max = max($OAT);
###################################################################################   
 
  
 
 ///// DE AICI INCEPE GRAFICUL 
 require_once("lib/phpchartdir.php"); 


# Sample data for the Box-Whisker chart. Represents the minimum, 1st quartile,
# medium, 3rd quartile and maximum values of some quantities
$Q0Data = array($luni_min, $marti_min, $miercuri_min, $joi_min, $vineri_min, $simbata_min, $duminica_min,0);
$Q1Data = array($luni_25th_percentile, $marti_25th_percentile, $miercuri_25th_percentile, $joi_25th_percentile, $vineri_25th_percentile, $simbata_25th_percentile, $duminica_25th_percentile,0);
$Q2Data = array($luni_50th_percentile, $marti_50th_percentile, $miercuri_50th_percentile, $joi_50th_percentile, $vineri_50th_percentile, $simbata_50th_percentile, $duminica_50th_percentile,0);
$Q3Data = array($luni_75th_percentile, $marti_75th_percentile, $miercuri_75th_percentile, $joi_75th_percentile, $vineri_75th_percentile, $simbata_75th_percentile, $duminica_75th_percentile,0);
$Q4Data = array($luni_max, $marti_max, $miercuri_max, $joi_max, $vineri_max, $simbata_max, $duminica_max,0);

# The labels for the chart
$labels = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday","k");

# Create a XYChart object of size 550 x 250 pixels
$c = new XYChart(550, 250);

# Set the plotarea at (50, 25) and of size 450 x 200 pixels. Enable both horizontal
# and vertical grids by setting their colors to grey (0xc0c0c0)
$plotAreaObj = $c->setPlotArea(50, 25, 450, 200);
$plotAreaObj->setGridColor(0xc0c0c0, 0xc0c0c0);

# Add a title to the chart
$c->addTitle("Computer Vision Test Scores");

# Set the labels on the x axis and the font to Arial Bold
$labelsObj = $c->xAxis->setLabels($labels);
$labelsObj->setFontStyle("arialbd.ttf");

# Set the font for the y axis labels to Arial Bold
$c->yAxis->setLabelStyle("arialbd.ttf");

# Add a Box Whisker layer using light blue 0x9999ff as the fill color and blue (0xcc)
# as the line color. Set the line width to 2 pixels
$boxWhiskerLayerObj = $c->addBoxWhiskerLayer($Q3Data, $Q1Data, $Q4Data, $Q0Data,
    $Q2Data, 0x9999ff, 0x0000cc);
$boxWhiskerLayerObj->setLineWidth(2);

# output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));  
  
  
  
  

?>

  Re: Cannot modify header information
Posted by Peter Kwan on Dec-07-2010 00:03
Hi poe,

Your probably already know that you cannot insert HTML into an image. Also, you cannot insert any image in HTML (you can only insert an <IMG> tag to reference an image). Also, in PHP, anything that is in <?php ... ?> is PHP code, and anything that is outside is HTML.

The error message is because that your code is trying to output both HTML and an image, which is illegal in HTTP standard. When your code outputs HTML, PHP will automatically sends the HTTP header to mark the MIME type as "text/html". If your code later tries to output an image by marking the MIME type as "image/png" (which is illegal in HTTP standard), PHP will produce error.

I can see your code outputs HTML. For example, the first line in your code is an empty line, and the second line contains some leading spaces. They are outside the <?php ... ?> block, so the empty line and the space characters are HTML. Also, I see your code includes "percentile.class.php". I am not sure what is in "percentile.class.php", but if there are empty lines or empty space, they are regarding as HTML too. Since your code outputs HTML, it is illegal for it to also output an image.

To solve the problem, please do not output HTML. Remove all empty spaces and lines outside of the <?php ... ?> block from "2BW.php" and "percentile.class.php" and make sure there are no other lines that can output HTML (no "echo", "print" and no other commands will emit notice or warning messages).

Hope this can help.

Regards
Peter Kwan

  Re: Cannot modify header information
Posted by poe on Dec-07-2010 02:27
Now work.
Thanks Peter