0

To get things in the open, there is nothing being output to the screen. There are no additional or conflicting header calls. I have in some cases the example scenario:

page.php

<?php

include('../../folder/session.php');

header("Location: http://www.ebay.com");
exit;

?>

session.php

<?php
    session_start();
?>

When you run page.php, it will throw the awful, ugly, makes-me-cuss-so-much-im-blue:

Warning: Cannot modify header information - headers already sent by

error

HOWEVER,

if I modify page.php to show:

<?php
     session_start();

header("Location: http://www.ebay.com");
exit;

?>

I wish I could say I was over simplifying the issue but that is exactly what is occuring. The same happens when i include several other 'includes' as well and literally is driving me bonkers.

JM4
  • 6,740
  • 18
  • 77
  • 125
  • The "headers already sent" error message should tell you exactly where (file and line number) the output is being sent before your header line – Mark Baker Mar 12 '11 at 00:55
  • @Mark Baker - no it doesnt. It says the output it sent at the same line as the header call. – JM4 Mar 12 '11 at 01:03
  • in that case, you have some form of customised, non-standard error message. The error message should read something like: "Cannot modify header information - headers already sent by (output started at XXX.php:999) in YYY.php on line 111" where XXX.php is the file with the output and 999 is the line number for that output, while YYY.php is the file with your header() and line 111 is the line with that header() – Mark Baker Mar 12 '11 at 08:22

3 Answers3

2

you probably have a blank space at the end of session.php

konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
2

Your session.php file probably has some sort of trailing white space that is being sent to the browser. Make sure there is no empty space or blank lines beneath or above .

As a hack you can use ob_start() to delay output but that will introduce the need to flush the output buffer. Better to just take care of extraneous white space.

vicTROLLA
  • 1,554
  • 12
  • 15
0

You can leave off the ?> at the end of your PHP files as well to eliminate this very problem. It has saved me many a headache.

Kevin
  • 512
  • 4
  • 15