|
Posted by amygdala on 08/10/07 18:47
"Rik" <luiheidsgoeroe@hotmail.com> schreef in bericht
news:op.twuwcnszqnv3q9@metallium...
On Fri, 10 Aug 2007 20:07:03 +0200, amygdala <noreply@noreply.com> wrote:
> First off: sorry about the empty posts people. I pushed accidentally
> pushed
> the send button (twice :-S ).
>
> "amygdala" <noreply@noreply.com> schreef in bericht
> news:46bc9d79$0$25487$9a622dc7@news.kpnplanet.nl...
>>
>
> <snip (very useful info nonetheless :-) >
>
>> $target = 'http://www.example.com';
>> header("Location: $target");
>> echo 'You're be redirected to '.$target.'. Click <a
>> href="'.$target.'">here</a> if it doesn't work';
>> exit; //<-----IMPORTANT!
>>
>
> Well whatta you know!! As soon as I put this suggestion of yours after
> the
> header("Location: $target"); it works! And mind you, not necessarily the
> exit() part, but the echo part!! How strange is that? I'm loosing all
> sense
> of logic on this one.
>
> Could it be that Opera needs some kind of body content after a
> redirection
> header? Or could it perhaps be that Opera indeed thinks that it should
> redirect back to the login page again, since it is redirected to a page,
> that redirected to the login page in the first place. lol
Somehow, your posts don't get quoted properly by my newsreader (yes, its OE
:-S ), so I'll resort to my own:
<Rik>
Possiblity 1:
Opera -> Tools -> preferences -> Advanced -> Network -> Enable Automatic
Redirection.
It's enabled by default, but can be disabled for whatever purpose. All the
more reason why a header redirect should be accompanied by some
information one is redirected, and a script should die()/exit() after that.
</Rik>
I know, but it's not an issue.
<Rik>
Possibility 2:
Opera get's the redirect, but still has the page with the same URL in
cache, so decides to use that one. Set some header and/or html information
these pages should not be cached.
</Rik>
Yes, that's a reasonable assumption, I will look into that a little more.
<Rik>
Possibility 3:
The script isn't terminated after the first header-redirect, continues to
run, and effectively changes the redirect by a second header() call.
Putting an echo directly after it will force the headers to be sent, so
they cannot be replaced anymore, resulting in the first one being the only
one, and thus the one obeyed by the browser. Another example why one
should die()/exit() after a redirect.
<?php
//this will offcourse end in /second.html
header('Location: /first.html');
header('Location: /second.html');
?>
<?php
//this will end in /first.html
header('Location: /first.html');
flush();
header('Location: /second.html');
?>
</Rik>
Yes, that makes sense. Although my application should not behave this way,
since it only calls for one function in one controller class per page, I
will look into this a little more. I could very well be overlooking flaws in
my application logics.
Thanks for the great suggestions Rik. You've been very helpful.
Cheers!
[Back to original message]
|