Solved

Generate a simple code for mobile number verification

Posted on 2009-07-08
5
2,575 Views
Last Modified: 2016-09-17
Hello,

I'm building a social network that will allow users to send SMSs between them, but the mobile number of each user must be first verified. Therefore I need a PHP script to do the following:

1- Once the user has typed his mobile number, the script generates a simple code (like "634928") which will be valid only for that number and not another one and for a concrete time (1 minute, for example).

2- Then that code is sent via SMS through the gateway I use and received by the number's owner. (For this step I just need a variable which takes the verification code, and I'll make it to be sent via SMS).

3- He writes it in a form which will check if the code is valid (the same generated at the beginning) and if it's still within the predefined time (the one set before).

4- If everything is OK a variable called "$verified" will take "yes" as value, if not, the page will ask to check the code.

I hope it's easy to do...

Thanks!
0
Comment
Question by:loggindevelop
  • 2
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
abijelic earned 500 total points
ID: 24803808
You actualy need two pages.. one for creating and one for verifying or actualy  you can do it  in one page which recursively call itself.  or through javascript if its all on one page and in lets say 5 minutes timeframe

You could do something like this...   i have on purposly written with long variable names and coments so you could easly see what is going on

file 1 :  createRandomCode.php   and copy below code into it
<?
function make_seed() {
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);
};

function MakeRandomCode() {
$ResultKode="";
srand(make_seed());
$CounterX=0;

while ($CounterX<9):  // until length of random code equals 8 signs <9
{
$TemporaryRandomCode=rand(65,90); // choose random number in ASCII range

$RandomLetter=chr($TemporaryRandomCode);  // convert it to character

$ResultKode .=$RandomLetter;   //Add random character to ResultString

$counterX=$counterX+1;

};
endwhile;
return $ResultKode;
};
?>

create file  SendRandomSMScode:
<?
include("createRandomCode.php");
$mobileNumber='the mobile number';  // to this variable you add the mobile number you receive through form
SmsCode=MakeRandomCode();
$SQLCode="Insert into SMScode (SMSCode,Mobilenumber) values ("  . $SmsCode . "," . $mobileNumber . ");" ;
mysql_query($SQLCode,"NAMEOFDATABASE")

//Insert code to send code to SMS
 ?>

Now you just need to read data from database and if everything is ok set the result  to $verified.

if you need more explanation  feel free to contact me...

1
 

Author Comment

by:loggindevelop
ID: 24804452
Hello, abijelic,

Thank you for your so fast answer, but I started trying it, exacuting first the MakeRandomCode() function and it gave me an error: max execution time limit exeeded (30 sec). I think there's an error in the code, but I don't know where. Please, could you check everything?

Thanks!
0
 
LVL 2

Assisted Solution

by:abijelic
abijelic earned 500 total points
ID: 24812775
Yup.... fast is always wrong...
just fix the following line

$counterX=$counterX+1;  
and change it to
$CounterX=$CounterX+1;

The error is in fact that in one instance i typed CounterX with big C, and in another with small c :)
0
 

Author Closing Comment

by:loggindevelop
ID: 31601068
Thank you!
0
 

Expert Comment

by:abi jaya
ID: 41802978
Hi I am newbie to this field. How to run that above php code.

localhost /otpcode/SendRandomSMScode.php -  when i was run that code its displaying empty.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now