Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
?
349 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

564 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