sessions and redirecting in opera

This is a discussion on sessions and redirecting in opera within the PHP Language forums, part of the PHP Programming Forums category; On Fri, 10 Aug 2007 20:32:45 +0200, Michael Fesser <netizen@gmx.de> wrote: > .oO(amygdala) &...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #21 (permalink)  
Old 08-10-2007
Rik
 
Posts: n/a
Default Re: sessions and redirecting in opera

On Fri, 10 Aug 2007 20:32:45 +0200, Michael Fesser <netizen@gmx.de> wrote:

> .oO(amygdala)
>
>> Exactly. To top it off, I implemented this because I assumed that by not
>> doing so, Opera's session might not be commited before the redirect.

>
> Are you sure you really understood how sessions work? The browser's
> only task is to keep the session ID, that's it. The handling of the
> session itself - open, read, write, close - is done on the server.
> Sessions are browser-independent, there's nothing to commit.


Are you sure you understood how redirecting and sessions works? A script
that has sent a header redirect _can_ continue on and one, doing heavy
work that lasts for an x amount of time. The session will only be closed
automatically when the script ends. If the user is allready requesting the
following page it might slow him down considerably, as the session data
isn't made available untill the end of that renegade script...

So, if a session is no longer needed, it's a wise idea to close is, just
not very necessary in your normal garden variety of PHP scripts.

--
Rik Wasmus
Reply With Quote
  #22 (permalink)  
Old 08-10-2007
amygdala
 
Posts: n/a
Default Re: sessions and redirecting in opera


"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!


Reply With Quote
  #23 (permalink)  
Old 08-10-2007
Rik
 
Posts: n/a
Default Re: sessions and redirecting in opera

amygdala wrote:
> Somehow, your posts don't get quoted properly by my newsreader (yes,
> its OE :-S ), so I'll resort to my own:


OE Quotefix, a must-have for MSOE users :)


Reply With Quote
  #24 (permalink)  
Old 08-10-2007
Michael Fesser
 
Posts: n/a
Default Re: sessions and redirecting in opera

..oO(Rik)

>On Fri, 10 Aug 2007 20:32:45 +0200, Michael Fesser <netizen@gmx.de> wrote:
>
>> Are you sure you really understood how sessions work? The browser's
>> only task is to keep the session ID, that's it. The handling of the
>> session itself - open, read, write, close - is done on the server.
>> Sessions are browser-independent, there's nothing to commit.

>
>Are you sure you understood how redirecting and sessions works?


Yes.

>[...]
>
>So, if a session is no longer needed, it's a wise idea to close is, just
>not very necessary in your normal garden variety of PHP scripts.


That's all correct - I was just picking on the "Opera's session might
not be commited before the redirect". Maybe it was just written in a
misleading way, but some problems simply cannot be related to a
particular browser.

And since I'm an Opera fan as well (since v3.60) ... ;-)

Micha
Reply With Quote
  #25 (permalink)  
Old 08-13-2007
amygdala
 
Posts: n/a
Default Re: sessions and redirecting in opera

Rik wrote:
> amygdala wrote:
>> Somehow, your posts don't get quoted properly by my newsreader (yes,
>> its OE :-S ), so I'll resort to my own:

>
> OE Quotefix, a must-have for MSOE users :)


Thanks for the tip Rik! Installed it. Seems to work like a charm.


Reply With Quote
  #26 (permalink)  
Old 08-13-2007
amygdala
 
Posts: n/a
Default Re: sessions and redirecting in opera

Rik wrote:
> On Fri, 10 Aug 2007 20:07:03 +0200, amygdala <noreply@noreply.com>
> wrote:
>>
>> 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

>
> 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.
> 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.
>
> 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');


This thing still has me puzzled. What I did is the following:

My SessionHandler class has the following method:

public function redirect( $url )
{
session_write_close();
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );
header( 'HTTP/1.0 302 Moved Temporarily' );
header( 'Location: ' . $url );
// this part between the comments is important
echo 'You\'re being redirected to ' . $url . ' .
Click <a href="' . $url. '">here</a> if it doesn\'t work';
// end important part
exit(); // exit doesn't really make a difference for Opera
}

Since I have now included the exit() statement I am sure that this is the
last thing done by the application when redirecting. Also, I have added
cache control headers and the likes. But still in Opera the problem persists
if I leave out the echo part you see above between the comments.

So, from my experience it seems as if Opera wants some body content for the
redirect to work and revalidate the url I landed on before I had to log in.

Does anyone have any other clue as to what might be going on here?

Thanks.


Reply With Quote
  #27 (permalink)  
Old 08-13-2007
Jerry Stuckle
 
Posts: n/a
Default Re: sessions and redirecting in opera

amygdala wrote:
> Rik wrote:
>> On Fri, 10 Aug 2007 20:07:03 +0200, amygdala <noreply@noreply.com>
>> wrote:
>>> 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

>> 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.
>> 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.
>>
>> 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');

>
> This thing still has me puzzled. What I did is the following:
>
> My SessionHandler class has the following method:
>
> public function redirect( $url )
> {
> session_write_close();
> header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
> header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
> header( 'Cache-Control: no-store, no-cache, must-revalidate' );
> header( 'Cache-Control: post-check=0, pre-check=0', false );
> header( 'Pragma: no-cache' );
> header( 'HTTP/1.0 302 Moved Temporarily' );
> header( 'Location: ' . $url );
> // this part between the comments is important
> echo 'You\'re being redirected to ' . $url . ' .
> Click <a href="' . $url. '">here</a> if it doesn\'t work';
> // end important part
> exit(); // exit doesn't really make a difference for Opera
> }
>
> Since I have now included the exit() statement I am sure that this is the
> last thing done by the application when redirecting. Also, I have added
> cache control headers and the likes. But still in Opera the problem persists
> if I leave out the echo part you see above between the comments.
>
> So, from my experience it seems as if Opera wants some body content for the
> redirect to work and revalidate the url I landed on before I had to log in.
>
> Does anyone have any other clue as to what might be going on here?
>
> Thanks.
>
>


Why are you sending a message they will never see, anyway? Normally a
redirect header has NO text associated with it.

If you have your header set up appropriately, they will be redirected.
All the message might do is screw things up for the browser.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #28 (permalink)  
Old 08-13-2007
amygdala
 
Posts: n/a
Default Re: sessions and redirecting in opera


"Jerry Stuckle" <jstucklex@attglobal.net> schreef in bericht
news:xqKdnb9U2fBnMyLbnZ2dnUVZ_uLinZ2d@comcast.com. ..
> amygdala wrote:
>>
>> This thing still has me puzzled. What I did is the following:
>>
>> My SessionHandler class has the following method:
>>
>> public function redirect( $url )
>> {
>> session_write_close();
>> header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
>> header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
>> header( 'Cache-Control: no-store, no-cache, must-revalidate' );
>> header( 'Cache-Control: post-check=0, pre-check=0', false );
>> header( 'Pragma: no-cache' );
>> header( 'HTTP/1.0 302 Moved Temporarily' );
>> header( 'Location: ' . $url );
>> // this part between the comments is important
>> echo 'You\'re being redirected to ' . $url . ' .
>> Click <a href="' . $url. '">here</a> if it doesn\'t work';
>> // end important part
>> exit(); // exit doesn't really make a difference for Opera
>> }
>>
>> Since I have now included the exit() statement I am sure that this is the
>> last thing done by the application when redirecting. Also, I have added
>> cache control headers and the likes. But still in Opera the problem
>> persists if I leave out the echo part you see above between the comments.
>>
>> So, from my experience it seems as if Opera wants some body content for
>> the redirect to work and revalidate the url I landed on before I had to
>> log in.
>>
>> Does anyone have any other clue as to what might be going on here?
>>
>> Thanks.

>
> Why are you sending a message they will never see, anyway? Normally a
> redirect header has NO text associated with it.
>
> If you have your header set up appropriately, they will be redirected. All
> the message might do is screw things up for the browser.


Because as Rik has pointed out earlier: some browsers might not obey the
request for a redirect. I predominantly browse using Opera, and in Opera,
you can also *choose* not to be redirected automatically. So having said
that, it makes sense to add an extra option for visitors, when they are not
redirected automatically.


Reply With Quote
  #29 (permalink)  
Old 08-13-2007
amygdala
 
Posts: n/a
Default Re: sessions and redirecting in opera


"Jerry Stuckle" <jstucklex@attglobal.net> schreef in bericht
news:xqKdnb9U2fBnMyLbnZ2dnUVZ_uLinZ2d@comcast.com. ..
> amygdala wrote:
>> Rik wrote:
>>> On Fri, 10 Aug 2007 20:07:03 +0200, amygdala <noreply@noreply.com>
>>> wrote:
>>>> 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
>>> 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.
>>> 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.
>>>
>>> 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');

>>
>> This thing still has me puzzled. What I did is the following:
>>
>> My SessionHandler class has the following method:
>>
>> public function redirect( $url )
>> {
>> session_write_close();
>> header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
>> header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
>> header( 'Cache-Control: no-store, no-cache, must-revalidate' );
>> header( 'Cache-Control: post-check=0, pre-check=0', false );
>> header( 'Pragma: no-cache' );
>> header( 'HTTP/1.0 302 Moved Temporarily' );
>> header( 'Location: ' . $url );
>> // this part between the comments is important
>> echo 'You\'re being redirected to ' . $url . ' .
>> Click <a href="' . $url. '">here</a> if it doesn\'t work';
>> // end important part
>> exit(); // exit doesn't really make a difference for Opera
>> }
>>
>> Since I have now included the exit() statement I am sure that this is the
>> last thing done by the application when redirecting. Also, I have added
>> cache control headers and the likes. But still in Opera the problem
>> persists if I leave out the echo part you see above between the comments.
>>
>> So, from my experience it seems as if Opera wants some body content for
>> the redirect to work and revalidate the url I landed on before I had to
>> log in.
>>
>> Does anyone have any other clue as to what might be going on here?
>>
>> Thanks.

>
> Why are you sending a message they will never see, anyway? Normally a
> redirect header has NO text associated with it.
>
> If you have your header set up appropriately, they will be redirected. All
> the message might do is screw things up for the browser.
>


PS.: Correct me if I'm wrong, but are my headers not set up properly?


Reply With Quote
  #30 (permalink)  
Old 08-13-2007
Jerry Stuckle
 
Posts: n/a
Default Re: sessions and redirecting in opera

amygdala wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> schreef in bericht
> news:xqKdnb9U2fBnMyLbnZ2dnUVZ_uLinZ2d@comcast.com. ..
>> amygdala wrote:
>>> Rik wrote:
>>>> On Fri, 10 Aug 2007 20:07:03 +0200, amygdala <noreply@noreply.com>
>>>> wrote:
>>>>> 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
>>>> 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.
>>>> 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.
>>>>
>>>> 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');
>>> This thing still has me puzzled. What I did is the following:
>>>
>>> My SessionHandler class has the following method:
>>>
>>> public function redirect( $url )
>>> {
>>> session_write_close();
>>> header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
>>> header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
>>> header( 'Cache-Control: no-store, no-cache, must-revalidate' );
>>> header( 'Cache-Control: post-check=0, pre-check=0', false );
>>> header( 'Pragma: no-cache' );
>>> header( 'HTTP/1.0 302 Moved Temporarily' );
>>> header( 'Location: ' . $url );
>>> // this part between the comments is important
>>> echo 'You\'re being redirected to ' . $url . ' .
>>> Click <a href="' . $url. '">here</a> if it doesn\'t work';
>>> // end important part
>>> exit(); // exit doesn't really make a difference for Opera
>>> }
>>>
>>> Since I have now included the exit() statement I am sure that this is the
>>> last thing done by the application when redirecting. Also, I have added
>>> cache control headers and the likes. But still in Opera the problem
>>> persists if I leave out the echo part you see above between the comments.
>>>
>>> So, from my experience it seems as if Opera wants some body content for
>>> the redirect to work and revalidate the url I landed on before I had to
>>> log in.
>>>
>>> Does anyone have any other clue as to what might be going on here?
>>>
>>> Thanks.

>> Why are you sending a message they will never see, anyway? Normally a
>> redirect header has NO text associated with it.
>>
>> If you have your header set up appropriately, they will be redirected. All
>> the message might do is screw things up for the browser.
>>

>
> PS.: Correct me if I'm wrong, but are my headers not set up properly?
>
>


Well, I don't see why you have the session_write_close() - the session
will be closed during exit() processing, anyway.

I also don't see why you have all of the cache control stuff. It's
completely unnecessary in this case.

Keep it simple - the 302 moved and location should be all you need.

And quite frankly, I wouldn't worry about opera users who disable the
redirects. After all - if you did the redirect in the normal way
(.htaccess or httpd.conf file), they wouldn't get a message. So they
must be used to getting blank screens.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0