Solved

Generate a simple code for mobile number verification

Posted on 2009-07-08
5
3,253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP - How to insert data using sqlsrv on stored procedure? 8 60
Format Date 7 28
sitemap.xml 3 32
Phone number mask 4 14
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

751 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