Why is php returning header issues when calling includes from different directories? [duplicate]
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.
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.
you probably have a blank space at the end of session.php
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.
精彩评论