php - 如果用户在过去 60 天内未在 codeigniter 中登录,则重定向到重置密码页面

标签 php mysql sql database codeigniter

我有一个用户表,我将用户登录时间存储在时间戳列中,数据类型为 int(11)。我正在尝试检查哪些用户在过去 60 天内没有登录并将他们重定向到重置密码页面。任何人都可以帮助我如何做到这一点?

这是我的 Controller :

public function login_user() {
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean', 'required');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean', 'required');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('login_view');
    } else {
        $data = array(
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password')
        );
        $result = $this->Login_model->login($data);
        $sessionres = $this->Login_model->sessionStore($data);

        if ($result == 1) {
            $userData = $this->Login_model->getUserData($data);
            $sessionArray = array(
                'is_logged' => TRUE,
                'user_name' => $data['username'],
                'first_name' => $userData['firstname'],
                'last_name' => $userData['lastname'],
                'userlevel' => $userData['userlevel'],
                'organisation_id' => $userData['organisation_id'],
                'user_id' => $userData['id'],
                'lastip' => $userData['lastip']

            );
            $this->session->set_userdata($sessionArray);
            redirect('dashboard');
        } else if ($result == 2) {
            $this->session->set_flashdata('message', 'Password seems to be wrong!');
            $this->load->view('login_view', $data);
        } else if ($result == 4) {
            $this->session->set_flashdata('message', 'Username is not active!');
            $this->load->view('login_view', $data);
        }else {
            $this->session->set_flashdata('message', 'Username not found!');
            $this->load->view('login_view', $data);
        }

    }
}

最佳答案

好吧,如果您有用户上次登录的时间戳,那么您可以检查它是否在最近两个月内,如果不是,则将用户重定向到密码重置页面。

假设您的用户上次登录时间为 $userData['timestamp'] , 然后就在 redirect('dashboard'); 之前你可以添加这样的东西:

$this->session->set_userdata($sessionArray);

if ($userData['timestamp'] > strtotime('-2 months')){
    redirect('dashboard');
    die();
}else{
    redirect('reset-password');
    die();
}

我假设 'reset-password'是密码重置页面的路径,$userData['timestamp']包含用户上次登录的时间。

希望对您有所帮助!

关于php - 如果用户在过去 60 天内未在 codeigniter 中登录,则重定向到重置密码页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51286946/

相关文章:

php - 在 XSLT 中进行文件路径操作

php - PHP Timeclock (PHP Mysql) 中统计每天的登录次数

linux - mysqld 无法启动,Angstrom 中缺少/etc/default/rcS

sql - 当快速加载选项打开且最大插入提交大小设置为零时,SSIS 如何重定向 OLEDB 目标中的行

java - 无需安装任何软件即可在局域网上通信两个html页面

mysql - 根据另一个表的数据获取列的总和

php - mysql查询从两个表中获取电影及其歌曲

c# - 建立中央 SqlConnection 的最佳方式

mysql - sql在两列分组内排序

php - 如何在php中上传和显示头像?