I am doing a project of using OTP for the login of the websites, I have created a button named "Generate" once clicked it will create an OTP and send an SMS via HTTP gateway, then it stores the password in the database.
My code to create an OTP and save in DB:
if(isset($_POST['generate']))
{
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string_shuffled = str_shuffle($string);
$password = substr($string_shuffled, 1, 7);
$password = base64_encode($password);
$query = mysql_query("UPDATE user_login SET password='".$password."' WHERE username = 'ajai sandy' ");
$qry_run = mysql_query($query);
}
Now I need to place this code of SMS API:
http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=xyz&to=919898123 456&sid=senderid&msg=test%20message&fl=0
The thing is the 5th line of code generates the OTP, then I need to place my SMS API after this so that it could send the password to the mobile, then it should encrypt the password which is on the 6th line and then saves in the database.
Am not sure how to perform this action in sequence and don't know where to place the code
Try this.
if(isset($_POST['generate']))
{
$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string_shuffled = str_shuffle($string);
$password = substr($string_shuffled, 1, 7);
file_get_contents("http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=$password&to=919898123456&sid=senderid&msg=test%20message&fl=0");
$password = base64_encode($password);
$query = mysql_query("UPDATE user_login SET password='".$password."' WHERE username = 'ajai sandy' ");
$qry_run = mysql_query($query);
}
The following code works like a charm ,
header('Location:http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=$password&to=919898123456&sid=senderid&msg=test%20message&fl=0');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With