1、修改这个文件 /var/Widget/User.php
①、增加一个属性,用来存放当前登录用户是否过期的状态
![图片[1]-Typecho二开之新增用户过期判断方法-米克随笔](https://blog.mk4.cc/wp-content/uploads/2022/07/image-49.png)
/**
* 是否已经登录
*
* @access private
* @var boolean
*/
private $_hasLogin = NULL;
②、增加一个方法,用来处理过期逻辑
/**
* 判断用户是否过期
*
* @access public
* @return boolean
*/
public function hasExtime()
{
if (NULL !== $this->_hasExtime) {
return $this->_hasExtime;
} else {
$cookieUid = Typecho_Cookie::get('__typecho_uid');
if (NULL !== $cookieUid) {
/** 验证登陆 */
$user = $this->db->fetchRow($this->db->select()->from('table.users')
->where('uid = ?', intval($cookieUid))
->limit(1));
if($user['exp_time']>time()){
return ($this->_hasExtime = true);
}
}
return ($this->_hasExtime = false);
}
}
2、以上两个内容新增以后,就可以在需要判断用户是否过期的地方调用,案例如下
if($this->user->hasExtime()){
echo '未过期';
}else{
echo '已过期';
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容