使用 Zend_Auth 设置和延长会话生命周期

发布于 2024-09-28 02:28:14 字数 1544 浏览 4 评论 0原文

我在我的一个项目中使用 Zend_Auth,但到目前为止还没有弄清楚如何设置会话的生命周期,或者如何延长它(假设它应该运行 5 分钟,并且应该在用户执行操作时重置为该值) ),这是我的初始化代码:

        $authAdapter = new Zend_Auth_Adapter_DbTable($this->_model->pdo);
        $authAdapter->setTableName('normal_folks')
           ->setIdentityColumn('username')
           ->setCredentialColumn('password');

        $post = $this->_request->getPost();

        $authAdapter->setIdentity($post['username'])
            ->setCredential($post['password']);
        $auth = Zend_Auth::getInstance();
        $result = $auth->authenticate($authAdapter);

        if($result->isValid())
        {
            $userInfo = $authAdapter->getResultRowObject(null, 'password');
            $authStorage = $auth->getStorage();
            $authStorage->write($userInfo);

            if(strlen($post['refferer']) > 1){
                header("Location: ".$post['refferer']);
            }elseif(strlen($this->_request->getParam('ref_action')) > 1){
                Zend_Controller_Action::_forward($this->_request->getParam('ref_action'),"admin",null,null);
            }else{
                Zend_Controller_Action::_forward("index","admin",null,null);
            }
        }

Ant 这是我检查用户是否登录的方式:

                if(Zend_Auth::getInstance()->hasIdentity()){
                    echo "Woho!";
                }else{
                    die("invalid-identity");
                }

它可能就在我面前,但我就是无法弄清楚,帮忙吗?请?漂亮吗? :D

i use Zend_Auth for one of my Projects, but so far haven't figured out how to set the Lifetime for the Session, or how to extend it (lets say it should run 5 minutes and should reset to that when the user makes an action), here is my Initialization code:

        $authAdapter = new Zend_Auth_Adapter_DbTable($this->_model->pdo);
        $authAdapter->setTableName('normal_folks')
           ->setIdentityColumn('username')
           ->setCredentialColumn('password');

        $post = $this->_request->getPost();

        $authAdapter->setIdentity($post['username'])
            ->setCredential($post['password']);
        $auth = Zend_Auth::getInstance();
        $result = $auth->authenticate($authAdapter);

        if($result->isValid())
        {
            $userInfo = $authAdapter->getResultRowObject(null, 'password');
            $authStorage = $auth->getStorage();
            $authStorage->write($userInfo);

            if(strlen($post['refferer']) > 1){
                header("Location: ".$post['refferer']);
            }elseif(strlen($this->_request->getParam('ref_action')) > 1){
                Zend_Controller_Action::_forward($this->_request->getParam('ref_action'),"admin",null,null);
            }else{
                Zend_Controller_Action::_forward("index","admin",null,null);
            }
        }

Ant this how i check if the user is logged in:

                if(Zend_Auth::getInstance()->hasIdentity()){
                    echo "Woho!";
                }else{
                    die("invalid-identity");
                }

Its probably right there in front of me but I just can't figure it out, help? Please? Pretty Please? :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

下壹個目標 2024-10-05 02:28:14

身份验证状态存储在注册的身份验证存储中。默认情况下,这是 Zend_Session。您可以设置过期时间< code>Zend_Auth 命名空间,例如

$namespace = new Zend_Session_Namespace('Zend_Auth');
$namespace->setExpirationSeconds(300);

您还可以 全局配置 Zend_Session 通过

Zend_Session::setOptions(array(
    'cookie_lifetime' => 300,
    'gc_maxlifetime'  => 300));

Authentication state is stored in the registered Auth Storage. By default this is Zend_Session. You can set an expiration time to the Zend_Auth namespace, e.g.

$namespace = new Zend_Session_Namespace('Zend_Auth');
$namespace->setExpirationSeconds(300);

You can also globally configure Zend_Session via

Zend_Session::setOptions(array(
    'cookie_lifetime' => 300,
    'gc_maxlifetime'  => 300));
初相遇 2024-10-05 02:28:14

如果您为 zend_auth 会话使用不同的命名空间,您可以这样做:

$auth = Zend_Auth::getInstance ();
$auth->setStorage ( new Zend_Auth_Storage_Session ( 'user' ) );

$namespace = new Zend_Session_Namespace('user');
$namespace->setExpirationSeconds(7200); // 2 hours

If you are using different namespace for zend_auth session you can do it like this:

$auth = Zend_Auth::getInstance ();
$auth->setStorage ( new Zend_Auth_Storage_Session ( 'user' ) );

$namespace = new Zend_Session_Namespace('user');
$namespace->setExpirationSeconds(7200); // 2 hours
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文