How can I access zend session in some other application that is integrated with it

286 Views Asked by At

I am running a Zend Framework application and I have to integrate a third party chat application and for that I need to have access of signed in user's ID, How can I access this id that is stored in Zend session.

Because this is not working

if (!empty($_SESSION['Zend_Auth']['storage']->user_id)) {
$userid = $_SESSION['Zend_Auth']['storage']->user_id;
}
2

There are 2 best solutions below

1
amirmohammad On

you can use this to get user id from storage

$userInfo = Zend_Auth::getInstance()->getStorage()->read();
echo $userInfo->user_id;
1
Stoyan Dimov On

If you feel more comfortable using your approach ($_SESSION) you can do it like this:

if (!empty($_SESSION['Zend_Auth']['storage']['user_id'])) { // <- Changed from '->' to ['']
    $userid = $_SESSION['Zend_Auth']['storage']['user_id']; // <- same as above
}

Hope this helps :)