5

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

iceangel89
  • 6,113
  • 8
  • 40
  • 55
  • 3
    how do you do your authentication? how do you make sure it is persisted? if you have done authentication right, hasIdentity will return true! – markus Sep 24 '09 at 08:28
  • i used Zend_Auth for authentication, http://framework.zend.com/manual/en/zend.auth.html#zend.auth.introduction.persistence.default, according to that $result->getIdentity() === $auth->getIdentity() – iceangel89 Sep 24 '09 at 10:39

3 Answers3

11

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.

gnarf
  • 105,192
  • 25
  • 127
  • 161
1

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

NDM
  • 6,731
  • 3
  • 39
  • 52
1

i had the same problem, in my case the value of session.save_path on was not set on my server (phpinfo()) so i added in configs/application.ini this value:

resources.session.save_path = APPLICATION_PATH "/../data/sessions"

and on my server i create the dir /data/sessions where sessions has 777 permissions

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
Ehecatl
  • 122
  • 1
  • 6