Wednesday, December 1, 2010

Re: $_SESSION contains my data but $Session helper is empty.

Come to think of it, I think I had this problem once or twice whilst tinkering around, I assumed it was something to do with my local dev server.

Good job on discovering the source of your session woes.

On 30 November 2010 21:44, amfriedman <amfriedman@gmail.com> wrote:
Actually, after about a day of mucking around in the core, I solved
the problem.  It is just a little "gotcha" with the way Cake loads
start_session(), or so it seems.

I've reproduced the bug with a clean copy of Cake 1.3.6.  The reason
why the Session helper fails is only if you have browser output (like
debug output) in the beforeFilter() function of AppController or
anywhere sooner in the dispatching process.

To test, just type some pr() statement in
AppController::beforeFilter(), and then try to reproduce my original
problem above, and you'll see that the Session helper fails.  BUT, if
you put something like $this->Session->check('blah') (even if 'blah'
is a nonexistent session key) BEFORE your pr() statement in
beforeFilter(), then the Session helper succeeds.

I believe the reason is because session_start() is not called early
enough in the application, but seems to be called on the first
instance of using the Session component (or helper), and if headers
have already been sent to the browser, session_start() fails.  (Though
it is failing silently with my PHP error reporting set to ALL.)

Yuck!  I'm glad I solved it though.  I've reported issue in Lighthouse.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en



--
Kind Regards
 Stephen @ NinjaCoderMonkey

 www.ninjacodermonkey.co.uk


Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: