Hii am doing a poject 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 a 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 ecnrypt the password which is on the 6th line and then save in the database.

Am not sure how to perform this action in sequence and dont know where to place the code

php sql api login otp

share|improve this question

asked Mar 12 at 13:04

Ajai Sandy

95

     

@krishna am having both the codes but am not sure how to place them with one another .. I need to generate an OTP then send the password to mobile via sms . Then save the password in db under encryption – Ajai Sandy Mar 12 at 13:11

add a comment

2 Answers

activeoldestvotes

up vote

0

down vote

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);

       }

share|improve this answer

answered Mar 12 at 13:35

Nishant Solanki

1,0791317

     

it says "failed to open stream" , the url is suppose to send a request to the server "smsgateway.com" – Ajai Sandy Mar 12 at 13:50

     

than you need to check your SMS api link.... – Nishant Solanki Mar 12 at 17:40

     

I took the SMS api link and pasted in my browser url bar and hit the period key , its working like a charm . But when placed inside the coding its generating the error " failed to open stream" – Ajai Sandy Mar 13 at 1:26

     

use like this.. echo file_get_contents("http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&p‌​wd=pwd&to=919898123456&sid=senderid&msg=your-password-is-$password%20message&fl=0‌​"); – Nishant Solanki Mar 13 at 4:54

add a comment

up vote

0

down vote

accepted

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');

For More Detail : http://stackoverflow.com/questions/22352471/how-to-generate-opt-and-send-the-password-to-mobile-via-sms