dsgdf45654
2017-03-06 13:43
浏览 76
已采纳

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

I want to set the session time out for OTP,after set the time OTP will expire

Controlller code as shown in below

    $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'] = "
";
                    $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条回答 默认 最新

  • dse3168 2017-03-06 14:02
    已采纳

    you can use this to expire your OTP:

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

    Here 300 is seconds, which means your 'otp' session will expire after 5 minute. For more information please refer https://www.codeigniter.com/user_guide/libraries/sessions.html .

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题