Basic session usage - namespace not storing variables

View: New views
3 Messages — Rating Filter:   Alert me  

Basic session usage - namespace not storing variables

by tony stamp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, i am new to the zf and a bit confused about using the session objects. I am using the session component but not within an MVC environment.

In my bootstrap i have:

Zend_Session::start();
Zend_Session::setOptions(array('strict' => 'true'));

which is the first thing included by every page. In my login page i have this:

//if db credentials are ok
$loginNamespace = new Zend_Session_Namespace('login');
$loginNamespace->loginUserID = $userId;
$loginNamespace->loginUserPassword = $userPassword;
$loginNamespace->loginType = $loginType;
$loginNamespace->lock();

now after the user has logged in, i am trying to check the session credentials on another page:
//after bootstrap has been included
$loginSessionNamespace = Zend_Session::namespaceGet('login');
        foreach($loginSessionNamespace as $key => $val){
                echo "$key is $val<br />";
        }
but no values are being printed. If i print_r($loginSessionNamespace ) i get:

Array ( [loginType] => ) loginType is

...??? Can someone just double check that i am using the session objects in the correct way?

Re: Basic session usage - namespace not storing variables

by Bart McLeod :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

As far as I know these values are available in the next request, not immediately after setting them. If you need them in the same request, put them in Zend_Registry::set($key, $value)

Bart

tony stamp schreef:
Hello, i am new to the zf and a bit confused about using the session objects.
I am using the session component but not within an MVC environment.

In my bootstrap i have:

Zend_Session::start();
Zend_Session::setOptions(array('strict' => 'true'));

which is the first thing included by every page. In my login page i have
this:

//if db credentials are ok
$loginNamespace = new Zend_Session_Namespace('login');
$loginNamespace->loginUserID = $userId;
$loginNamespace->loginUserPassword = $userPassword;
$loginNamespace->loginType = $loginType;
$loginNamespace->lock();

now after the user has logged in, i am trying to check the session
credentials on another page:
//after bootstrap has been included
$loginSessionNamespace = Zend_Session::namespaceGet('login');
	foreach($loginSessionNamespace as $key => $val){
		echo "$key is $val<br />";
	}
but no values are being printed. If i print_r($loginSessionNamespace ) i
get:

Array ( [loginType] => ) loginType is 

...??? Can someone just double check that i am using the session objects in
the correct way?

  

Re: Basic session usage - namespace not storing variables

by tony stamp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It is on another page - another request:

> now after the user has logged in, i am trying to check the session
> credentials on another page:
LightInTheBox - Buy quality products at wholesale price