Solved

Generate a simple code for mobile number verification

Posted on 2009-07-08
5
2,757 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Headphone jack broken? Do you notice the picture quality is better on a different device? If your Samsung Galaxy Note 3 is giving you headaches, this guide will run down a list of things you can do to improve its lifespan.   Phone Will Not Turn O…
Once again I push the limits of my phone.  An introduction to the Android Google Now Launcher.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

9 Experts available now in Live!

Get 1:1 Help Now