How to Pass A Session Variable in Zend To Native PHP

123

I want to pass a variable from Zend frame work to a native php file in the same server.

what i tried

$auth = Zend_Auth::getInstance();
     if($auth->hasIdentity())
        {

          $user = $auth->getIdentity();
          $username33 = $this->escape(ucfirst($user->username));
          $_SESSION['thisisnotit']=$username33;
       }

then i tried this in my php page

echo $notit = $_SESSION['thisisnotit'];

Obviously this gave me an error. I understand the syntax of sessions in Zend is

$myNamespace = new Zend_Session_Namespace('myNamespace');

but how do i get this to work so that i can access the varible in my php file

87

Answer

Solution:

Your goal is to get auth service. So, for that or for any service you want, first you need to load ZF2 application to get your auth service. Following working/tested code to achieve this -

require 'init_autoloader.php';
// Run the application!
$app=Zend\Mvc\Application::init(require 'config/application.config.php');
$authService=$app->getServiceManager()->get('AuthenticationService');
echo 'Session Data: <pre>'.print_r($authService->getIdentity(), true);

More efficient way is welcome.

People are also looking for solutions to the problem: mysql - while loop not working for more than one variable php?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.