How can I unserialize Symfony session from the file?

前端 未结 1 871
粉色の甜心
粉色の甜心 2021-01-22 03:24

Symfony store session in the app/cache/dev/sessions/sess_{session_id} file in dev env. The file\'s content is something like:

_sf2_attributes|a:0:{}         


        
相关标签:
1条回答
  • 2021-01-22 03:58

    You can just use standard PHP session mechanism. You need to set up the directory where your sessions is stored (app/cache/dev/sessions). And then calling standard function session_start() will fill the $_SESSION variable with all unserialized data from appropriate file.

    For example you can use this code:

    ini_set('session.save_handler', 'files');
    ini_set('session.save_path', 'path/to/your/site/folder/app/cache/dev/sessions');
    session_start();
    

    The way described above can be used when you need to work with sessions behind Symfony framework (as OP needs). To use Symfony's session mechanism you should work with Session object that will provide you all the needed information:

    use Symfony\Component\HttpFoundation\Session\Session;
    
    $session = new Session();
    $session->start();
    
    $session->all(); // will return unserialized array of parameters
    
    0 讨论(0)
提交回复
热议问题