Yii Framework Forum: 关于Yii的Cwebuser中Logout方法的疑问 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

关于Yii的Cwebuser中Logout方法的疑问 Rate Topic: -----

#1 User is offline   PHP_KUN 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 14-September 12

Posted 28 January 2013 - 02:16 AM

public function logout($destroySession=true)
{
    if($this->beforeLogout())
    {
        if($this->allowAutoLogin)
        {
            Yii::app()->getRequest()->getCookies()->remove($this->getStateKeyPrefix());//销毁$_COOKIE['$this->getStateKeyPrefix()']
            if($this->identityCookie!==null)//identityCookie这个属性找不到在哪有赋值过!这里不清楚!我以为是用户选择了记住登录状态后,在用户注销时保存一些下次能直接登录用的cookie,
            {
                $cookie=$this->createIdentityCookie($this->getStateKeyPrefix());
                $cookie->value=null;
                $cookie->expire=0;//但这里,当设置cookie过期时间为0或者忽略不设置的情况下,cookie将会在session过期后过期(即浏览器关闭后cookie过期)
                Yii::app()->getRequest()->getCookies()->add($cookie->name,$cookie);
            }
        }
        if($destroySession)
            Yii::app()->getSession()->destroy();
        else
            $this->clearStates();
        $this->afterLogout();
    }
}

看了源码,如果用户登录时选择了记住我,则会生成cookie,但是在退出时的logout,有疑问,它先把之前生成的cookie删除,下面判断CWebUser的identityCookie属性是否为空,这个在用户登录时(选择了记住我)哪里有被赋值过?,如果没有那就为空,那下次登录时用的cookie是那来的?
请指教~谢谢~
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users