• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

yii框架,设置自动登录以后,如何捕捉登录动作

php 搞代码 4年前 (2022-01-24) 35次浏览 已收录 0个评论

yii框架,设置自动登录以后,怎么捕捉登录动作?
用的yii,实现了自动登录。现在的问题是,需要在用户登录的时候,记录下登录时间,请问应该在哪里做呢?
我现在是在component的 useridentity类下的authenticate方法里,记录用户登录时间的,但是貌似会漏掉。用户选自动登录的时候,有的时候貌似记录不到。

大大们,应该怎么弄啊?
——解决方案————–

!本文来源gaodai.ma#com搞##代!^码网(

搞gaodaima代码——
大概是yiilite.php文件中的以下几行代码实现的自动登陆。我想你能看出原因来

<br />public function init()<br />	{<br />		parent::init();<br />		Yii::app()->getSession()->open();<br />		if($this->getIsGuest() && $this->allowAutoLogin)<br />			$this->restoreFromCookie();<br />		else if($this->autoRenewCookie && $this->allowAutoLogin)<br />			$this->renewCookie();<br />		if($this->autoUpdateFlash)<br />			$this->updateFlash();<br />		$this->updateAuthStatus();<br />	}<br />	public function login($identity,$duration=0)<br />	{<br />		$id=$identity->getId();<br />		$states=$identity->getPersistentStates();<br />		if($this->beforeLogin($id,$states,false))<br />		{<br />			$this->changeIdentity($id,$identity->getName(),$states);<br />			if($duration>0)<br />			{<br />				if($this->allowAutoLogin)<br />					$this->saveToCookie($duration);<br />				else<br />					throw new CException(Yii::t('yii','{class}.allowAutoLogin must be set true in order to use cookie-based authentication.',<br />						array('{class}'=>get_class($this))));<br />			}<br />			$this->afterLogin(false);<br />		}<br />	}<br />

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:yii框架,设置自动登录以后,如何捕捉登录动作
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址