?
Solved

Urgent -- Warning: Cannot modify header information - headers already sent by (output started at C:\PHP Notes\PHPExamples\parserproject\sample6.php:1) in C:\PHP\pear\Writer.php on line 67

Posted on 2005-03-16
6
Medium Priority
?
329 Views
Last Modified: 2011-09-20
Hello
 Im always getting the warning cannot modify header info
Actually i m using  the Spreadsheet_Excel_Writer-0.8  in this there is a file called writer.php in which the warnig is pointed

My code is

 <?php
 require_once 'Writer.php';
 // Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();

// sending HTTP headers
$workbook->send('SampleMonster.xls');

// Creating a worksheet
$worksheet =& $workbook->addWorksheet('Monster1');

 $i=0;
 $tempState= true;
 $filename = "SBC_Monster1.mbx";
 $fp = fopen( $filename,"r") or die("Couldn't open $filename");
 
 while ( ! feof( $fp ) ) {
 
 
  $line = fgets( $fp, 1024 );
  if (!preg_match("/(<.html>)/", $line, $matches))
  {
      if (preg_match ("/(<\b(FirstName)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match ("/(<\b(LastName)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match ("/(<\b(Address1)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
              $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match ("/(<\b(City)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            if(!$arEmployee[$i][$arTmp[2]] = "")
            {
              $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
            }
      }
      if (preg_match ("/(<\b(StateAbbrev)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            if($tempState)
            {
              $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
              $tempState =false;
            }
      }
      if (preg_match ("/(<\b(PostalCode)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match ("/(<\b(CountryAbbrev)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }      
      if (preg_match ("/(<\b(EmailAddress)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match ("/(<\b(PhoneType)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
      //$arEmployee[$arTmp[2]] = $arTmp[3];      
      if (preg_match ("/(<\b(Number)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp1))
            $arEmployee[$i][$arTmp[3]] = $arTmp1[3];      
      }
      if (preg_match ("/(<\b(ContactPreference)[^>]*>\b)(.*)(<\/\\2>)/", $line, $arTmp))
      {
            $arEmployee[$i][$arTmp[2]] = $arTmp[3];      
      }
      if (preg_match("/Desired Salary./", $line, $arTmp))
      {
            $nextline = fgets( $fp, 1024 );      
            $expSal = strip_tags($nextline);
            $arEmployee[$i][$arTmp[0]] = $expSal;
      }
      
  }
  else
  {
    //print_r ($arEmployee[$i]);
    //print "</BR>";
    //print "</BR>";
    //print "</BR>";
    //print "</BR>";
    $i=$i+1;
    $tempState= true;
  }
 }
 print $i;




      
$worksheet->write(0, 0, 'FirstName');
$worksheet->write(0, 1, 'LastName');
      
for ($j=0;$j<=$i;$j++)
{
 foreach ( $arEmployee[0] as $key=>$value ) {
      if($key == "FirstName")
      {
      $worksheet->write($j+1, 0, $value);
      }
      if($key == "LastName")
      {
      $worksheet->write($j+1, 1, $value);
      }
 }
 }
 
 //Let's send the file
$workbook->close();
 ?>



writer.php  is

<?php
/*
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
*  PERL Spreadsheet::WriteExcel module.
*
*  The author of the Spreadsheet::WriteExcel module is John McNamara
*  <jmcnamara@cpan.org>
*
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
*  porting of this code to PHP.  Any questions directly related to this
*  class library should be directed to me.
*
*  License Information:
*
*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation; either
*    version 2.1 of the License, or (at your option) any later version.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public
*    License along with this library; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

require_once('PEAR.php');
require_once('Spreadsheet/Excel/Writer/Workbook.php');

/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author   Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package  Spreadsheet_Excel_Writer
*/

class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
{
    /**
    * The constructor. It just creates a Workbook
    *
    * @param string $filename The optional filename for the Workbook.
    * @return Spreadsheet_Excel_Writer_Workbook The Workbook created
    */
    function Spreadsheet_Excel_Writer($filename = '')
    {
        $this->_filename = $filename;
        $this->Spreadsheet_Excel_Writer_Workbook($filename);
    }

    /**
    * Send HTTP headers for the Excel file.
    *
    * @param string $filename The filename to use for HTTP headers
    * @access public
    */
    function send($filename)
    {
        header("Content-type: application/vnd.ms-excel");   //here is ther problem all five lines are giving warning
        header("Content-Disposition: attachment; filename=$filename");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
        header("Pragma: public");
    }


Thanx in advance
0
Comment
Question by:babuno5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 2000 total points
ID: 13557116
This problem is usually caused by output being sent prior to the headers.  Common causes are blank lines, spaces, or other white space before the <?php in either writer.php or sample6.php.  Make very certain that absolutely nothing appears before the first <?php in either file.
0
 
LVL 15

Author Comment

by:babuno5
ID: 13557196
i have tried to remove spaces from Writer.php but still no result
0
 
LVL 15

Author Comment

by:babuno5
ID: 13557231
i have removed all spaces from the writer.php which is as follows

<?php
/*
*  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
*  PERL Spreadsheet::WriteExcel module.
*
*  The author of the Spreadsheet::WriteExcel module is John McNamara
*  <jmcnamara@cpan.org>
*
*  I _DO_ maintain this code, and John McNamara has nothing to do with the
*  porting of this code to PHP.  Any questions directly related to this
*  class library should be directed to me.
*
*  License Information:
*
*    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets
*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
*    This library is free software; you can redistribute it and/or
*    modify it under the terms of the GNU Lesser General Public
*    License as published by the Free Software Foundation; either
*    version 2.1 of the License, or (at your option) any later version.
*
*    This library is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    Lesser General Public License for more details.
*
*    You should have received a copy of the GNU Lesser General Public
*    License along with this library; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
require_once('PEAR.php');
require_once('Spreadsheet/Excel/Writer/Workbook.php');
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author   Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package  Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
{
    /**
    * The constructor. It just creates a Workbook
    *
    * @param string $filename The optional filename for the Workbook.
    * @return Spreadsheet_Excel_Writer_Workbook The Workbook created
    */
    function Spreadsheet_Excel_Writer($filename = '')
    {
        $this->_filename = $filename;
        $this->Spreadsheet_Excel_Writer_Workbook($filename);
    }
    /**
    * Send HTTP headers for the Excel file.
    *
    * @param string $filename The filename to use for HTTP headers
    * @access public
    */
    function send($filename)
    {
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
    }
.
.
.
.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:snoyes_jw
ID: 13557412
The line
 print $i;
in the sample file could also do it.
0
 
LVL 15

Author Comment

by:babuno5
ID: 13557430
that was just for debugging
anyways removed it but still no result
0
 
LVL 15

Author Comment

by:babuno5
ID: 13557601
thanks a lot for the help the problem is solved
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question