Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3

Thread: Header Error...

  1. #1
    Senior Member joncom11's Avatar
    Join Date
    Oct 2003
    Posts
    284
    Member #
    3532
    I keep getting the following error with my script:

    Code:
    Warning: Cannot add header information - headers already sent by (output started at /users/ionichost.com/swa/get.php3:6) in /users/ionichost.com/swa/get.php3 on line 29
    
    Warning: Cannot add header information - headers already sent by (output started at /users/ionichost.com/swa/get.php3:6) in /users/ionichost.com/swa/get.php3 on line 30
    I am using the following script:

    Code:
    <?php
    @extract($_POST);
    ?>
    
    <title>Downloading....</title>
    <meta http-equiv="refresh" content="5;URL=<?php echo $PHP_SELF; ?>">
    <body background="images/dlbg.jpg" leftmargin="0" topmargin="0">
    <table width="468" border="0" cellpadding="0" cellspacing="0">
    <script type="text/javascript" src="java.js"></script>
      <!--DWLayoutTable-->
      <tr> 
        <td width="101" height="32">&nbsp;</td>
        <td width="330">&nbsp;</td>
        <td width="37">&nbsp;</td>
      </tr>
      <tr>
        <td height="195">&nbsp;</td>
        <td valign="top">You will be redirected to the download site in 5 seconds!
    	or, if you do not want to wait, please click <a href="<?php echo $PHP_SELF; ?>">here!</a></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td height="73">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <?php
    Header ( "Content-Type: application/octet-stream"); 
    Header( "Content-Disposition: attachment; filename=$saveas"); 
    readfile($download); 
    ?>
    How can I stop getting this error?
    Pixel Fuse - Signature webpage, just a spashpage.
    Flash Frogger - Frogger remake, animated/coded in Flash (incomplete/discontinued)
    Daase Art Studio - Homepage of David Daase, a Canadian landscape artist - image gallery/showcase.
    More links if I think of some...

  2.  

  3. #2
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    I can give you a general answer.

    Everytime output is sent to a browser(text, images, whatever), headers are autogenerated. You cannot send new headers to the same page after the header stream is sent, that will generate an error like the one you're getting.

    If you want to send headers using php on a page that contains other output (like text etc), you have to make sure the headers are sent before the server starts generating output of any type. That means the header info has to be on top of the page, absolute first line (no blank spaces in front of the php tag, and no trailing spaces after the closing tag)

    If the script containing/generating header info is on a different page, there will be no problem.
    S. Rosland

  4. #3
    Member nepharo's Avatar
    Join Date
    Jun 2003
    Posts
    73
    Member #
    1729
    In other words: Make sure your script does not output anything to the browser, not even spaces, before calling the header function. So you can do things like this
    Code:
    <?
    $var1 = "whaterver";
    
    $var2 = "foobar";
    
    header("location: /foo/bar.html");
    
    ?>
    But you can't do this
    Code:
    <?
    
    $var1 = "foo";
    
    echo $var; // error here, it's outputing something to the browser prior to calling header()
    
    header("location: /foo/bar.html");
    ?>
    outputing regular html(not withing php) is also dissalowed
    I cannot self terminate, you must lower me into the fire.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:44 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com