$ _SESSION in zend doesn't work
I am new to zend framework and I would like to use $ _SESSION, but after starting a session using session_start and storing a session variable, I cannot access that variable in another page.
I know we can use the Zend session namespace, but for some reason I would like to stick with $ _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'];
Controller-specific output2
is a test comment for the session
source to share
you need to go to config /autoload/global.php and add session config 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 at all session_start()
. Then you can establish or read sessions without any problem.
source to share
Why do you want to access the session directly? This is all handled by the Zend Framework. Use a session manager instead ( http://framework.zend.com/manual/current/en/modules/zend.session.manager.html ). It provides an abstraction layer.
source to share