Results 1 to 2 of 2

Thread: How to dictate the session storage with Zend_Session_Namespace?

  1. #1
    darrenl is offline Junior Member
    Join Date
    May 2010
    Posts
    8

    Arrow How to dictate the session storage with Zend_Session_Namespace?

    Hi all, I have been able to set the storage engine when I use Auth, but when I call a regular Zend_Session_Namespace will it know to store my sessions in the right place? Here is my simple code calling a new session, and my token class:
    Code:
    <?php
    
    class Share_Auth_Token
    {
    	protected $_session;
    
    	/**
    	 * Constructor
    	 *
    	 */
    	public function __construct()
    	{
    		$this->_session = new Zend_Session_Namespace('auth_token');
    	}
    	
    	/**
    	 * Setup
    	 * @param int $expiration
    	 */
    	public function setup($expiration = NULL)
    	{
    		if (is_null($expiration)) {
    			$expiration = 900;	
    		}
    		
    		$this->_session->setExpirationSeconds($expiration); 
    		$this->_session->auth_token = $hash = md5(uniqid(rand(), 1)); 
    	}
    	
    	/**
    	 * Token
    	 * @return string
    	 */
    	public function getToken()
    	{
    		return $this->_session->auth_token;
    	}
    
    	/**
    	 * Check
    	 * @param string $auth_token
    	 * @return boolean
    	 */
    	public function checkToken($auth_token = NULL)
    	{
    		if (is_null($auth_token)) {
    			$auth_token = '';	
    		}
    		
    		if ($this->_session->auth_token == $auth_token) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    }
    In my auth module I dictate the storage engine as follows:
    Code:
    <?php
    
            $auth = Zend_Auth::getInstance();
            $auth->setStorage(new Zend_Auth_Storage_Session($this->_module == 'admin' ? 'Zend_Auth_Admin' : 'Zend_Auth_User'));

    Is there a way I could dictate the storage engine in the token class?

    Thanks,
    Darren

  2. #2
    darrenl is offline Junior Member
    Join Date
    May 2010
    Posts
    8

    Default

    Hi all, I got it. It turns out if a class is shared module wide settings don't apply, so I just had it decide based on which module it was in.

Similar Threads

  1. Zend OpenID Provider DB Storage
    By johnjackson in forum Authentication & Authorization
    Replies: 3
    Last Post: 01-22-2011, 08:58 PM
  2. Zend_Session_Namespace data corruption ('css')
    By vian in forum Authentication & Authorization
    Replies: 0
    Last Post: 02-12-2010, 11:18 AM
  3. Zend_Auth storage fails to persist
    By schacko in forum Authentication & Authorization
    Replies: 1
    Last Post: 10-02-2008, 09:44 PM
  4. Zend_Session_Namespace::setExpirationHops()
    By MiK in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 06-26-2008, 01:46 PM
  5. Using custom storage session
    By pablo in forum Authentication & Authorization
    Replies: 1
    Last Post: 03-19-2008, 05:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •