PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] How can I unserialize Symfony session from the file?

 December 28, 2021     php, serialization, session, symfony     No comments   

Issue

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:{}_sf2_flashes|a:0:{}_sf2_meta|a:3:{s:1:"u";i:1396424236;s:1:"c";i:1396360957;s:1:"l";s:1:"0";}bbb|i:222;IsAuthorized|b:1;

When I try to unserialize it with unserialize() function - I get FALSE.

How can I unserilize this?


Solution

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


Answered By - Michael Sivolobov
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing