Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Auth checking if user is logged in

I tried using:

// do login if request is posted
if (isset($_POST) && !empty($_POST)) {
    // do authencation
    ...
} else {
    // request not posted
    // see if already logged in
    if (Zend_Auth::getInstance()->hasIdentity()) {
        echo "already logged in as: " . Zend_Auth::getInstance()->getIdentity();
    }
}

Zend_Auth::getInstance()->hasIdentity() seem to be always false ... even after a login

like image 257
iceangel89 Avatar asked Sep 24 '09 08:09

iceangel89


2 Answers

Are you ever calling Zend_Auth::getInstance()->getStorage()->write($identity)?

If you are authenticating through Zend_Auth::getInstance()->authenticate($adapter) it will write to storage for you, but if you are calling authenticate directly on the adapter, you are responsible for writing the identity to the storage.

like image 187
gnarf Avatar answered Oct 26 '22 12:10

gnarf


are you sure your identity is persisted? (ie. stored in the session or somthing similar) if not you will have to re-authenticate on each request

like image 45
NDM Avatar answered Oct 26 '22 11:10

NDM