简体   繁体   中英

$_SESSION in zend not working

I am new to zend framework and I would like to use $_SESSION, but after I start the session using session_start and store a session variable, I am not able to access that variable on another page.

I know that we can use Zend session namespace but for some reason I would like to stick to $_SESSION.

in controller 1 ->
session_start();
$_SESSION['uid']=$this->_user_id;

in controller 2
session_start();
echo 'this is test comment for session '.$_SESSION['uid'];

Output in view of controller2
this is the test comment for session

you need to go to the config/autoload/global.php and add session configuration there if it is not:

'session' => array(
    'config' => array(
        'class' => 'Zend\Session\Config\SessionConfig',
        'options' => array(
            'name' => 'myapp',
        ),
    ),
    'storage' => 'Zend\Session\Storage\SessionArrayStorage',
    'validators' => array(
        'Zend\Session\Validator\RemoteAddr',
        'Zend\Session\Validator\HttpUserAgent',
    ),
),

you don't need to use session_start() at all. Then you can set or read sessions without any problem.

Why do you want to access the Session directly? That's all handled by Zend Framework. Please use the Session Manager ( http://framework.zend.com/manual/current/en/modules/zend.session.manager.html ) instead. It provides an abstraction layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM