$from, 'to' => $to, 'text' => $message, ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $api_url.'/v2/accounts/'.$accountSID.'/messages'); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1); // Set user and password curl_setopt ($curl, CURLOPT_USERPWD, $accountSID.':'.$password); // Do not check SSL curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // Add header curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // Set POST curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($body)); $result = curl_exec($curl); if ($result) { $result = json_decode($result, true); } else { $result = array( 'error_text' => curl_error($curl), 'error_code' => curl_errno($curl), 'status_code' => 600, ); } return $result; } /** * This function generates random numeric code. This code is sent via SMS to verify the phone number. * @param number $length * @return string */ function generateCode($length = 5) { srand(time()); $chars = "1234567890"; $ln = strlen($chars); $pwd = ""; for($i = 0; $i < $length; $i++) { $pos = rand(0, $ln - 1); $pwd .= $chars[$pos]; } return $pwd; } /** * Set default variables */ // Specify Apifonica API URL $api_url = 'https://api.apifonica.com'; // Specify your Apifonica account SID $accountSID = ''; // Specify your Apifonica account password $password = ''; // Specify the message sender's number (this number must be mobile number belonging to the Apifonica account you have specified) $from = ''; /** * Set variables from POST */ $action = isset($_POST['action'])?$_POST['action']:'default'; $name = isset($_POST['name'])?trim($_POST['name']):''; $phone = isset($_POST['phone'])?trim($_POST['phone']):''; $code = isset($_POST['code'])?trim($_POST['code']):''; $result = null; if ($action == 'send_verification') { $code = generateCode(); $_SESSION['__auth_code'] = $code; $result = sendSMS($api_url, $accountSID, $password, $from, $phone, $code); } else if ($action == 'check_verification') { $result = array(); if (!isset($_SESSION['__auth_code']) || $_SESSION['__auth_code'] != $code) { $result['error_text'] = 'Wrong verification code! Please, enter a valid code which is sent to the phone number you have provided.'; $result['status_code'] = 308; } else { $result['status_text'] = 'Registration is complete! Thank you!'; unset($_SESSION['__auth_code']); } } else { unset($_SESSION['__auth_code']); } /** * Default view form (Phone Number Verification) */ ?> Apifonica - send verification codes via SMS

299) { ?>

An error occured while sending the request :(

299) { ?>

Verify Your Mobile Number

  Try Another Number

Registration is complete! Thank you!

Register Another User

Phone Number Verification