我有一个用户表,我将用户登录时间存储在时间戳列中,数据类型为 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/