Mobile otp system in laravel

In most of our client websites they ask to implement login with otp . Today I will write on this topic about integrating the otp login system on the default login page of laravel. We also need a SMS api to send otp from our website code logic. So, be prepared for your SMS api.

otpsend

function otpsend(Request $request){

$curl = curl_init();
$sms_gateway_key = '80c8cba5-1e09-11e9-9ee8-0200cd936042';
$phone = '917746060757';
$rndno = rand(10000, 99999);

curl_setopt_array($curl, array(
CURLOPT_URL => "http://2factor.in/API/V1/".$sms_gateway_key."/SMS/".$phone."/".$rndno,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

return back()->with('message', 'OTP Sent to your Number!');

}

 

Leave a Reply