Why is session data empty in Symfony2 and how to access it?

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

A third-party PHP application stores data in the user's session (using a cookie for PHPSESSID). In this app, the $_SESSION variable contains all this data.

In my Symfony2 application, the same $_SESSION only contains some Symfony data (_sf2_attributes, _security_secured_area, _sf2_flashes, etc.) and I don't see any other data from the other app.

I did a var_dump of the $_SESSION variable in a controller to check this. Using the Symfony Session object shows the same data. The 2 apps use the same domain for storing the PHPSESSID cookie.

How can I get all data of the session in my Symfony app? I would like the session to be shared between the 2 applications.

回答1:

I finally solved the problem. Symfony stores its session data in its own directory (app/cache/[environment]/sessions). So the solution is to set the default session path in config.yml:

framework:     session:         save_path: ~ 

This will set the default path back (for example /var/lib/php5 on Linux) and the legacy app session data is made available to the Symfony app.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!