tags:

views:

63

answers:

1

Hello,

When I use header( 'Location: http://www.yoursite.com/new_page.html' ) ; which is a PHP redirection of page, it says header already passed at line....

The landing page as <? include('header.php'); ?>

How can I over come this error message?

Appreciate assistance.

Thanks Jean

+4  A: 

Note that headers should be sent before anything else. Make sure that there is no code/html or even space/indentation before the header function and there is nothing before the first opening php tag <?php as well as ending tag ?> in your page.

Sarfraz
The include file is placed at the top of the page, the error points on the previous page, at the point header(), thats whats confusing me!
Jean
@Jean: In which file header function is used, is it header.php or some other file, post your relevant code too.
Sarfraz
@jean if either page have anything printed to the page before header(); it will fail. Even ` <?php` will fail (note the space before the `<`)
hookedonwinter
I have one.php, here is where the redirection is triggered to two.php. the error says header already passed and points to a line on one.php
Jean
@Jean can you please edit your question with the entire contents of one.php?
hookedonwinter
@Jean: Make sure that there is no space/indentation/html/code before the header function as well as starting php tag `<php` and ending tag `?>` in your one.php page. Also see @hookedonwinter comment.
Sarfraz
@sarfraz @hookedonwinter I cannot post the code, because there are over 200 lines of code all from var to sql query statements. At one point when the a particular event is triggered the header() is triggered.
Jean
@Jean: Try removing the very last ending tag of php `?>` from your one.php page.
Sarfraz
@Jean alright. Is there any sort of echo, print_r, escaping out of php, or any other sort of printing on either page before the header() call?
hookedonwinter
The complete warning message will most likely narrow it down to a small section of the script.
VolkerK
@sarfraz @hookedonwinter @volkerk I found the solution using javascript window.location redirect, but still this seems to be tickling my brains.hmmm..yes there is one echo, can that be the reason?
Jean
@Jean without question. Anything printed before the header() will cause the header() to fail.
hookedonwinter
Please add the complete warning message to your question. Do it now, do not pass "Go!", do not collect $2000. But add the warning message.
VolkerK
@VolkerK `str_repeat( 'Please add the complete warning message to your question.', 500);` ;)
hookedonwinter
@Jean: Your javascript redirection will fail if it is disabled at user's computer, avoid it as much as possible when redirecting.
Sarfraz
@sarfraz it works....!!!
Jean
@Jean: That is good news then...we made it !
Sarfraz
@sarfraz header(location: '') does not work anywhere, I fail to understand, though I make use of the javascript redirect function. I removed all echo""; before the header(location:''); Any clues?
Jean
You need to enclose path in quotes like this `header("location: index.php")`
Sarfraz
have done that...
Jean
Well then only thing coming in my mind is check for errors, try putting these two lines on top of your page to see any errors: `ini_set('display_errors', true); error_reporting(E_ALL);`
Sarfraz
Its not just the header(); but couple of lines are before, no echo.
Jean
Try removing those lines to see if it makes any difference.
Sarfraz
If header() is the only line, then it works just fine...
Jean
it means you have problem in lines above header.
Sarfraz