i wish to access the $otp variable from line 8 of the below code ,but it gives me a different value i.e the value which i had input on the website when i try i acessing it from line 70 of the below code instead of returning the system generated value( i have confirmed that the system generates a value) from linre 8
<?php
include("include/connection.php");
if(isset($_POST['type']))
{
if($_POST['type']=='mobile'){
@$mobile=$_POST['mobile'];
$otp=generateOTP();
$_SESSION["signup_otp"] = $otp;
$chkuser=mysqli_query($con,"select * from `tbl_user` where `mobile`='".$mobile."'");
$userRow=mysqli_num_rows($chkuser);
if($userRow==''){
session_start();
unset($_SESSION["signup_mobile"]);
unset($_SESSION["signup_otp"]);
$_SESSION["signup_mobile"] = $mobile;
$_SESSION["signup_otp"] = $otp;
$fields = array(
"variables_values" => $otp,
"route" => "otp",
"numbers" => $mobile
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.fast2sms.com/dev/bulkV2",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"authorization: ",
"accept: */*",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo '1';
}
}else{
echo"2";
}
}
if($_POST['type']=='otpval'){
session_start();
$ot= $_POST['otp'];
print_r("postotp= ".$_POST["otp"]);
$mobile= $_SESSION["signup_mobile"];
$sessionotp= $_SESSION["signup_otp"];
print_r("sessionotp= ".$otp." u");
if($otp!==$ot) {
echo"0";
}else{
$_SESSION["signup_mobilematched"] = $_SESSION["signup_mobile"];
unset($_SESSION["signup_mobile"]);
unset($_SESSION["signup_otp"]);
echo"1";
}
}
}
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
the print_r() of line 67 gives the input value, and print_r() of line 70 also gives the same input value instead of returning the exact value of the variable $otp from line 8. can anyone help me to solve this?. thanks for any help!
the otp part of signup.php's form is gien beow for more ease.
<div class="col-4 pl-0"><a href="javascript:void(0);" class="btn btn-block btn-light otpbtn" id="reg_otp" onClick="mobileveryfication();">Send OTP</a></div>
the above code initiates the sending of the sms the js function calls the verifyotp.php file(the first php file in this post) and it sends an otp, until that it works fine,then
<form action="#" method="post" id="otpsubmitForm">
<input type="text" id="otp" name="otp" class="form-control" placeholder="Enter OTP" onKeyPress="return isNumber(event)">
<input type="hidden" name="type" id="type" value="otpval">
the problem is when the document asks me to submit the otp, and calls the verifyotp.php file again. this time the verifyotp.php file validates the otp and seds the result to javascript function which ony says that if 0 return the otp is wrong. else if 1 return true. hope this explanation will help u all tohelp me. :)