如何使用codeigniter为otp设置会话超时

时间:2017-03-06 13:43:04

标签: php codeigniter

我想在设置OTP到期的时间后设置OTP的会话超时

控制器代码如下所示

    $six_digit_random_number = mt_rand(100000, 999999);                
    $this->session->set_userdata('otp', $six_digit_random_number);
                    $this->load->model('Login_model');
     $pass['pass'] = $this->Login_model->forgot_pass_retrive($emailTo);
                    $config['protocol'] = 'smtp';
                    $config['smtp_host'] = 'ssl://smtp.gmail.com';
                    $config['smtp_port'] = '465';
                    $config['smtp_timeout'] = '7';
                    $config['smtp_user'] = 'tworkreport@gmail.com';
                    $config['smtp_pass'] = '87xxxxxxxx';
                    $config['charset'] = 'utf-8';
                    $config['newline'] = "\r\n";
                    $config['mailtype'] = 'text'; 
                    $config['validation'] = TRUE; 
                    $this->email->initialize($config);
       $this->email->from('tworkreport@gmail.com', 'Terasukhintrade');
                    $this->email->to($emailTo);
                    $this->email->subject('Reset your password');
                    $this->email->message('Click on link to reset your password '.$this->session->userdata['otp'] );

                    $this->email->send();

                    echo $this->email->print_debugger();

                    $this->load->view('login',$data);
                } else {

                    $this->session->set_flashdata('message', ' Email address not found!');
                    $this->load->view('login',$data);
                }

            }
        }

1 个答案:

答案 0 :(得分:0)

你可以用它来使你的OTP过期:

    $this->session->set_tempdata('otp', $six_digit_random_number, 300);

这里300秒是秒,这意味着你的' otp'会议将在5分钟后到期。 有关详细信息,请参阅yeld developers documentation