Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:08:35+00:00 2026-06-16T20:08:35+00:00

I have problem with a session in Symfony 2.1 for a site inside Symfony

  • 0

I have problem with a session in Symfony 2.1 for a site inside Symfony (in one controller).
I set the session like this:

 $this->get("session")
 ->set('UserMongoId', $this->get('security.context')->getToken()->getUser()->getId());

After that in another file (inside the web folder of Symfony) outside symfony 2.1, I do
this:

use Symfony\Component\HttpFoundation\Request;


$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('rpod', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();

$session = new \Symfony\Component\HttpFoundation\Session\Session();
$session->start();
var_dump ($session);

$user_id = $session->get("UserMongoId");

However I received null, and I dont know how to make it work, any ideas?

now I trying MongoDbSessionHandler and storage the session in db with mongo

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:08:37+00:00Added an answer on June 16, 2026 at 8:08 pm

    I get it store the session in db with mongo:

    1.- service.yml

    parameters:
        mongo.session.options:
            database: quorra_session
            collection: session
    services:
        mongo.connection:
            class: MongoDoctrine\MongoDB\Connection
            factory_service: doctrine.odm.mongodb.document_manager
            factory_method: getConnection
            calls:
               - [initialize, []]
        mongo:
            class: Mongo
            factory_service: mongo.connection
            factory_method: getMongo
    
        session.handler.mongo:
              class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler
              arguments: [@mongo, %mongo.session.options%]
    

    2.- confing.yml add :

      framework:
            session:
                handler_id: session.handler.mongo
    

    3.- after that doctrinemongo db with MongoDbSessionHandler will save all the session automatically in db perfect if we are going to work with direferents servers. will be something like that:

    { "_id" : ObjectId("50e60da9893ad520a11a7fd7"), "sess_data" : BinData(2,"pAMAAF9zZjJfYXR0cmlidXRlc3xhOjM6e3M6MTI6ImFjY2Vzc190b2tlbiI7czo1MDoiMTYzNDQzODUtYW52OVF6WmFQVDF0bHJ1ejk5OWdlU0w4U2Q1THdMQUxUSnA2V1lFaE0iO3M6MTk6ImFjY2Vzc190b2tlbl9zZWNyZXQiO3M6NDI6IlB4MDg1SWFEWktaUFBucHQ0UkRNbDRtV29VdGtQeFc0YkF4dmZzdkI2NCI7czoxNDoiX3NlY3VyaXR5X21haW4iO3M6NjMxOiJDOjY0OiJGT1NcVHdpdHRlckJ1bmRsZVxTZWN1cml0eVxBdXRoZW50aWNhdGlvblxUb2tlblxUd2l0dGVyVXNlclRva2VuIjo1NTM6e2E6Mjp7aTowO047aToxO3M6NTI4OiJhOjQ6e2k6MDtDOjMxOiJRdW9ycmFcQ29yZUJ1bmRsZVxEb2N1bWVudFxVc2VyIjoxODU6e2E6Mjp7aTowO047aToxO3M6MTYwOiJhOjk6e2k6MDtzOjA6IiI7aToxO3M6MzE6ImpkZWRyYnY4bmxzMDRvYzh3d2M0c29zb2MwazhzZzAiO2k6MjtzOjY6ImZhbmp1bCI7aTozO3M6NjoiZmFuanVsIjtpOjQ7YjowO2k6NTtiOjA7aTo2O047aTo3O2I6MTtpOjg7czoyNDoiNTBlNjBkYTlkNGMzOGVlOWMyMDAwMDAwIjt9Ijt9fWk6MTtiOjE7aToyO2E6Mjp7aTowO086NDE6IlN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcUm9sZVxSb2xlIjoxOntzOjQ3OiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxSb2xlXFJvbGUAcm9sZSI7czoxMjoiUk9MRV9UV0lUVEVSIjt9aToxO086NDE6IlN5bWZvbnlcQ29tcG9uZW50XFNlY3VyaXR5XENvcmVcUm9sZVxSb2xlIjoxOntzOjQ3OiIAU3ltZm9ueVxDb21wb25lbnRcU2VjdXJpdHlcQ29yZVxSb2xlXFJvbGUAcm9sZSI7czo5OiJST0xFX1VTRVIiO319aTozO2E6MDp7fX0iO319Ijt9X3NmMl9mbGFzaGVzfGE6MDp7fV9zZjJfbWV0YXxhOjM6e3M6MToidSI7aToxMzU3MjU0MTU0O3M6MToiYyI7aToxMzU3MjUzOTgzO3M6MToibCI7czoxOiIwIjt9"), "sess_id" : "f9a98866cd99a33d61204413b68d6ca5", "sess_time" : { "t" : 1357254155000, "i" : 3 } }
    

    4.- In one file outside symfony 2.1 ( i have the file now in web for not load the components )

    use Symfony\Component\ClassLoader\ApcClassLoader;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\Security\Core\SecurityContext;
    use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
    
    $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
    require_once __DIR__.'/../app/AppKernel.php';
    
    //$kernel = new AppKernel('prod', false);
    $kernel = new AppKernel('dev', true);
    $kernel->loadClassCache();
    
    $mongo = new Mongo();
    
    $options["database"] = "quorra_session";
    $options["collection"] = "session";
    
    $mongoSession = new MongoDbSessionHandler($mongo,$options);
    $data = $mongoSession->read($_COOKIE["PHPSESSID"]);
    

    and the variable data has all the session for this user.

    5.- Now, the next step is send to this last file the access_token_secret and check it in the result of $data = $mongoSession->read($_COOKIE[“PHPSESSID”]);

    works for me, I’m waiting for your comments

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have the following code: public function editAction(Request $request) { $user = $this->get('security.context')->getToken()->getUser(); //
I have implemented a listener on the security.interactive_login event to set one session variable
I have problem with session in cakephp.I have one file chat.php that is in
Weired problem! ASP.NET Session expires instantly. In my web.config I have this session settings:
I have a problem with Session.Clear(), as I understand it this statement should completely
I have problem. I have this code, and I can`t add session. This is
I am trying to use Symfony 2 security component, but I have a problem
I have problem with my spring-security.xml file. I have wanted to configure some session

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.