Php laravel中的Otp验证
我正在尝试在我的laravel应用程序中获得Otp验证系统 但是 当我输入我的号码以获得otp时,它显示我的页面已过期。已提供代码和屏幕截图页面已过期 使用MSG91 代码Php laravel中的Otp验证,php,laravel,one-time-password,Php,Laravel,One Time Password,我正在尝试在我的laravel应用程序中获得Otp验证系统 但是 当我输入我的号码以获得otp时,它显示我的页面已过期。已提供代码和屏幕截图页面已过期 使用MSG91 代码 <div class="container"> <div class="jumbotron"> <h1>OTP</h1> <div class="card"> <
<div class="container">
<div class="jumbotron">
<h1>OTP</h1>
<div class="card">
<div class="card-body">
<div class="col-md-6">
<form action="{{url('/')}}/dashboard" method="POST">
<div class="form-group">
<label for="exampleInputPassword1">Mobile Number</label>
<input type="number" class="form-control" id="number" name="number" placeholder="Enter Mobile Number">
</div>
<button type="submit" name="sendotp" class="btn btn-success">Send OTP</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
$authKey = "auth...Key...here";
$senderId = "Id here";
if (isset($_POST['sendotp'])){
$mobileNumber = $_POST['number'];
$message = 'Your Verification Code id ######';
$postData = array(
'authKey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
);
$url ="http://control.msg91.com/api/sendotp.php";
$curl = curl_init($url);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.msg91.com/api/v5/otp?invisible=1&otp=OTP%20to%20send%20and%20verify.%20If%20not%20sent%2C%20OTP%20will%20be%20generated.&userip=IPV4%20User%20IP&authkey=Authentication%20Key&email=Email%20ID&mobile=Mobile%20Number&template_id=Template%20ID&otp_length=&otp_expiry=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $postData,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
?>
错误。。
请让我知道我的错误在哪里。。。。
另外,请告诉我使用MSG91在laravel中添加OTP验证的最佳方法
谢谢您需要将csrf令牌与表单一起传递 {{csrf_field}} 手机号码 发送OTP 如果您使用的是laravel>5.6,也可以使用@csrf
{{csrf_field}}和@csrf都提供相同的隐藏字段。您需要以表单形式传递csrf令牌 {{csrf_field}} 手机号码 发送OTP 如果您使用的是laravel>5.6,也可以使用@csrf
{{csrf_field}}和@csrf都提供相同的隐藏字段。您应该真正清理代码。cURL调用在视图中没有位置,在Laravel中不建议使用$\u POST。您应该真正清理代码。cURL调用在视图中没有位置,在Laravel中不建议使用$\u POST。
{{ csrf_field() }} with generate a hidden field with name _token.
<input type="hidden" name="_token" value="token value">