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

Saturday, March 19, 2022

[FIXED] Yii::$app->session->getId() doesn't work in mongodb session component

 March 19, 2022     mongodb, php, session, yii     No comments   

Issue

Yii::$app->session->getId() returns an empty string.

How can I get the session id when I'm using the mongodb session component (yii\mongodb\Session)?

My config:

'session' => [
    'class' => 'yii\mongodb\Session',
    'writeCallback' => function($session)
        {
            return [
                'user_id' => Yii::$app->user->id,
                'agent' => Yii::$app->request->getUserAgent(),
                'ip' => Yii::$app->request->getUserIP(),
            ];
        }
]

Solution

You must open a session first.

Yii::$app->session->open();
return Yii::$app->session->id;


Answered By - mohammad zahedi
  • 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