How to generate an OTP and send to user in codeigniter 3

9.3k views Asked by At

I have an API project in codeigniter using Phil Sturgeon restful server (https://github.com/chriskacerguis/codeigniter-restserver), I need to generate OTP and sent it to users mobile,email while anyone registering to the app, if user submits the correct OTP then only the registration process will complete.

1

There are 1 answers

0
Ryuk Lee On

I think you can use string hepler to random OTP

$this->load->helper('string');
$otp = random_string('alnum', 6);
// add user info and $otp into database
// send $otp to user
// check the $otp user enter and update user status to actived

more info about string helper in CI https://www.codeigniter.com/user_guide/helpers/string_helper.html