'123456','user2' => '234567','user3' => '345678',);
$getmobile = array('user1' => '9930447726','user2' => '9769818858','user3' => '9619141191',);
/////////////////////////////////////////////////////////////////////////////
// Your Login Credentials with SMSGatewayCenter.com //
/////////////////////////////////////////////////////////////////////////////
$smsgatewaycenter_com_user = "YourUsername"; //Your SMS Gateway Center Account Username
$smsgatewaycenter_com_password = "********"; //Your SMS Gateway Center Account Password
$smsgatewaycenter_com_url = "https://www.yoursmsproviderdomain.com/library/send_sms_2.php?"; //SMS Gateway Center API URL
$smsgatewaycenter_com_mask = "SGCSMS"; //Your Approved Sender Name / Mask
/////////////////////////////////////////////////////////////////////////////
// Function to Initiate SMS Message with SMS Gatewaycenter.com using CURL //
/////////////////////////////////////////////////////////////////////////////
function smsgatewaycenter_com_Send($mobile, $sendmessage, $debug=false){
global $smsgatewaycenter_com_user,$smsgatewaycenter_com_password,$smsgatewaycenter_com_url,$smsgatewaycenter_com_mask;
$parameters = 'UserName='.$smsgatewaycenter_com_user;
$parameters.= '&Password='.$smsgatewaycenter_com_password;
$parameters.= '&Type=Individual';
$parameters.= '&Language=English';
$parameters.= '&Mask='.$smsgatewaycenter_com_mask;
$parameters.= '&To='.urlencode($mobile);
$parameters.= '&Message='.urlencode($sendmessage);
$apiurl = $smsgatewaycenter_com_url.$parameters;
$ch = curl_init($apiurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
if ($debug) {
echo "Response:
" . $curl_scraped_page . "
";
}
return($curl_scraped_page);
}
/////////////////////////////////////////////////////////////////////////////
// Function to generate and append OTP code within the message //
/////////////////////////////////////////////////////////////////////////////
function smsgatewaycenter_com_OTP($length = 8, $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789'){
$chars_length = (strlen($chars) - 1);
$string = $chars{rand(0, $chars_length)};
for ($i = 1; $i < $length; $i = strlen($string)){
$r = $chars{rand(0, $chars_length)};
if ($r != $string{$i - 1}) $string .= $r;
}
return $string;
}
/////////////////////////////////////////////////////////////////////////////
// If Debug is set to true below, then response from //
// SMSGatewayCenter.com API will be printed on the screen //
/////////////////////////////////////////////////////////////////////////////
$debug = false; //Set to true if you want to see the response
/////////////////////////////////////////////////////////////////////////////
// If user has not posted anything, lets load the user login page //
/////////////////////////////////////////////////////////////////////////////
if (empty($_POST)){
$i = 0;
echo '
One Time Password Form
';
}
/////////////////////////////////////////////////////////////////////////////
// If form has been submitted by the user, lets create OTP or validate //
/////////////////////////////////////////////////////////////////////////////
if (isset($_POST['sendsms'])){
$_SESSION['smsgatewaycenterotp'] = smsgatewaycenter_com_OTP(); //Generate OTP
/////////////////////////////////////////////////////////////////////////////
// Lets validate user credentials with getuserarray //
/////////////////////////////////////////////////////////////////////////////
$username = $_POST['username'];
$password = $_POST['password'];
if ($password != $getuser[$_POST['username']] || ((empty($_POST['username']) && (!empty($_POST['password'])))) || (empty($_POST['password']) && (!empty($_POST['username'])))){
echo 'Please enter a valid username or password!'; //username and password does not match
}
elseif ((!empty($_POST['submit'])) && (empty($_POST['password'])) && (empty($_POST['username']))){
echo 'No username or password entered'; //Empty form submitted
}
elseif ($password == $getuser[$_POST['username']]){
/////////////////////////////////////////////////////////////////////////////
// User has successfully validated credentials, lets append OTP and send //
// and send the SMS to recipient's mobile number to authenticate OTP //
/////////////////////////////////////////////////////////////////////////////
smsgatewaycenter_com_Send($getmobile[$_POST['username']],'Dear '.$username.'! Please authenticate your OTP. Your One Time password is: '.$_SESSION['smsgatewaycenterotp'],$debug);
echo '
Authenticate OTP (One Time Password)
We have sent an SMS to your registered phone number, please authenticate your one time password entering below.
';
}
}
elseif (isset($_POST['submitotp'])){
/////////////////////////////////////////////////////////////////////////////
// Lets validate user's OTP and validate with the stored session //
/////////////////////////////////////////////////////////////////////////////
$sgc_otp = $_POST['getsmsgatewaycenterotp'];
if($_SESSION['smsgatewaycenterotp'] == $sgc_otp){
echo '
You\'ve been successfully verified your One-Time Password
';
} else {
echo'
Wrong Password!
';
}
}