这是我在codeigniter控制器中使用的代码,这对我来说似乎不起作用。 contact.php = controller
function send()
{
$this->load->library('session');
$this->session->set_userdata('lastsent', microtime());
if(microtime() >= $this->session->userdata('lastsent') + 60000000)
{
// here I have all my send email code, that works.
...
$data['message'] = 'Email was sent, thank you.';
$this->load->view('contact', $data);
}
else
{
$data['message'] = 'Please wait 60 seconds.';
$this->load->view('contact', $data);
} //timeout check
} //send()
答案 0 :(得分:1)
您忘记在会话中添加数据:
$this->session->set_userdata('lastsent', 'Your data here');
例如:
$this->session->set_userdata('lastsent', microtime());
修改:尝试使用time()
代替microtime()
(不再支持microtime,时间到了)
function send()
{
$this->load->library('session');
$this->session->set_userdata('lastsent', time());
if(time() >= $this->session->userdata('lastsent') + 60)
{
$data['message'] = 'Email was sent, thank you.';
$this->load->view('contact', $data);
}
else
{
$data['message'] = 'Please wait 60 seconds.';
$this->load->view('contact', $data);
}
}