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
Solved

Generate a simple code for mobile number verification

Posted on 2009-07-08
5
3,021 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you’re having problems with your Nexus 4, you’ll want to take a look at this step-by-step troubleshooting guide that walks you through common issues and helps you solve them so that you can extend the life of your device.  Phone Won't Turn On…
Are you having trouble connecting or getting your iPhone / Samsung device(s) to sync with Microsoft Exchange Server?   What have you tried?   What haven't you tried?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

791 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