views:

874

answers:

2

I am using the app_error script to deal with broken links on my site, and in the error404() action I write a session value like this:

$this->controller->Session->write("visitor", $visitorId);

This all works as I can successfully read the session back if I reload app_error. Once I have written this session value I redirect to a controller:

$this->controller->redirect($redirectURL,301);

What I am then trying to do is to check this session value in the beforeFilter() callback in app_controller, but it just doesn't seem to be able to detect this value. Ive tried

$this->Session->read("visitor");

and it does not retrieve anything. I've also tried the check method.

Can anyone see anything obvious here? I have debug set to 0 (production) so it uses the error404() by default.

+1  A: 

Try setting the session value like this:

$this->Session->write("VisitorInfo.visitor","value");

Then you wont have any problems reading it from app_controller using:

$this->Session->read('VisitorInfo');
pcp
+1  A: 

Hrmm. Is your whole session being destroyed or are you not able to read that one index? I'm assuming your whole session is being destroyed. Is the page you are redirecting to on the same domain (and subdomain, if applicable)? Most of the time when I have a problem like this it has to do with cake aggressively destroying the session, especially if your Security.level is set to high/medium.

If your session is indeed being destroyed make sure that the both domains are the same. If this is already the case try moving your security level to low to make sure you're not being caught by the session.referer_check.

Otherwise you should definitely be able to read from the session in the beforeFilter().

JoeyP

related questions