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

如何使用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 .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗