Page 1 of 1

Cannot modify header information error

Posted: Wed Jan 28, 2009 4:44 pm
by fairyprincess18
im getting this error

Cannot modify header information - headers already sent by...

I have read most likely has to with there being existing whitespace somewhere in my php code, but I can't find it for the life of me.

The following code, which is generating the error is called via javascript and then exited upon completion:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>
        <?php
            $file = 'TVeedahlRes.txt';
            if (file_exists($file)) {
                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename='. basename($file));
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header('Pragma: public');
                header('Content-Length: ' . filesize($file));
                ob_clean();
                flush();
                readfile($file);
                exit;
            }
        ?>
    </body>
</html>
 
what is generating this error message?

Re: Cannot modify header information error

Posted: Wed Jan 28, 2009 4:55 pm
by nor0101
it's being caused by the first few lines of your file.

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head></head>
    <body>      
 
try moving your PHP script to the beginning of the first line of the file.

Re: Cannot modify header information error

Posted: Wed Jan 28, 2009 6:15 pm
by fairyprincess18
thanks, that did the trick