开发者

CakePHP dropping session between pages

I have an application with multiple regions and various incoming links. The premise, well it worked before, is that in the app_controller, I break out these incoming links and set them in the session.

So I have a huge beforeFilter() in my app_controller which catches these and sets two variables in the session. Viewing.region and Search.engine, no problem.

The problem arises that the session does not seem to be persistant across page requests. So for exampl开发者_StackOverflowe, going to /reviews/write (userReviews/add) should have a session available which was set when the user arrived at the site. Although it seems to have vanished!

It would appear that unless $this->params is caught explicitly in the app_controller and a session variable written, it does not exist on other pages.

So far I have tried, swapping between storing session in 'cake' and 'php' both seem to exhibit the same behaviour. I use 'php' as a default. My Session.timeout is '120', Session.checkAgent is False and Security.level is 'low'. All of which should give enough leniency to the framework to allow sessions the most room to live!

I'm a bit stumped as to why the session seems to be either recreated or blanked when a new page is being requested. I have commented out the requestAction() calls to make sure that isn't confusing the session request object also, which doesn't seem to make a difference.

Any help would be great, as I don't have to have to recode the site to pass all the various variables via parameters in the url, as that would suck, and it's worked before, thus switching on $this->Session->read('Viewing.region') in all my code!


Try setting the security setting in your /app/config/core.php file to medium or low. That solved a session problem I had.


i had the solution or at least that work for me

you try to pass from controller reviews action write to controller userReviews action add right???

check that your controller userReviews must end whit php tag "?>" and NO MORE SPACE

SO if you have someting like this

line
999 //more code lines
1000 ?>
1001

your session fail

you have to had this

line
999 //more code lines
1000 ?>

sorry for my bad english soo you


It would appear that unless $this->params is caught explicitly in the app_controller and a session variable written, it does not exist on other pages.

That sounds like the proper behavior unless you are posting data from page to page. If you want any variable to persist, it should either be set in the model (where it will persist with the association), or passed on in a function, or set in the session explicitly using the session component:

$this->Session->write('Viewing.region');

(see: http://book.cakephp.org/view/398/Methods)

On a related note, I've had most success with sessions stored in the database. Run the file from app/config and set it to db. See if that helps.

Also, do the Cake core tests for the session work?


Might it be this problem? Essentially, cake's session resets if the user-agent changes It's a shame that I ran into this very problem you mention a few days ago and now I cannot find the link that helped me solve it.

Also: are you using database or plain php sessions?


I'm going to go out on a limb here without being able to look at your code, but might it be possible that your "reviews" controller (or whatever) has its own beforeFilter() and doesn't call its parent's beforeFilter() explicitly?

This has burned me before...


I got some issues like this. Session set using some controller was not available in another , controller . I could clear the issue after spending few hours . There was a white space afer the end of php tag at the bottom . After clearing the line and white space after the last ?> tag worked fine .


I had this problem when moving a CakePHP site. My problem was that the session directory wasn't writeable. You should make sure the folder app/tmp and all it's subfolders (including sessions) have permission 777.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜