Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $("#phone").submit(function()
- {
- var phone_no = $('#phone_no').val();
- if(phone_no != '')
- {
- $.post("sendcode.php", { phone_no: phone_no },
- function(data)
- {
- $(".result").html(data);
- },
- "html"
- );
- }
- return false;
- });
- });
- </script>
- <div class = "result"></div>
- <p>Enter your phone number below, and we will send you a verification code to that phone number.</p>
- <form id = "phone" method = "POST" action = "">
- <label for = "phone">Phone number</label>
- <input name = "phone" type = "text" id = "phone_no" />
- <input name = "submit" type = "submit" value = "Send Verification Code" />
- </form>
- <p>Enter Verification Code received to the phone number specified above in the form below.</p>
- <form id = "verification" method = "POST" action = "verify.php">
- <label for = "code">Verification Code</label>
- <input name = "code" type = "text" id = "code" />
- <input name = "submit" type = "submit" value = "Verify" />
- </form>
- <?php
- if(isset($_POST['code']))
- {
- $verifyCode = $_POST['code'];
- /*** mysql hostname ***/
- $hostname = 'localhost';
- /*** database name ***/
- $dbname = 'sms';
- /*** mysql username ***/
- $username = 'root';
- /*** mysql password ***/
- $password = 'secret';
- try {
- $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
- // USER_ID is the login ID of the user
- $sql = "SELECT code FROM user WHERE id = {$user_id}";
- $sth = $dbh->query($sql);
- $code = $sth->fetchColumn();
- if($code == $verifyCode)
- {
- echo "Your account has been validated.";
- // verify user in db
- $todo = "UPDATE user SET status = 1 WHERE user_id = {$user_id}";
- $dbh->execute($todo);
- }
- else
- {
- echo "Your account has not been validated.";
- }
- $dbh = null;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- ?>
- <?php
- // configuration
- use TwilioRestClient;
- /*** mysql hostname ***/
- $hostname = 'localhost';
- // database name
- $dbname = 'sms';
- /*** mysql username ***/
- $username = 'root';
- /*** mysql password ***/
- $password = 'secret';
- // enter SID here
- $twilioSid = 'ACxxx';
- // enter twilio token here
- $twilioToken = 'TKxxx';
- if(isset($_POST['phone_no']))
- {
- try
- {
- $verifyCode = rand(1000, 9999);
- $phone = $_POST['phone_no'];
- $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
- /*** add verification code and phone number to db **/
- $sth = "INSERT INTO user (phone, code) VALUES(:phone, :code)";
- $command = $dbh->prepare($sth);
- $command->bindParam(':phone', $phone, PDO::PARAM_STR);
- $command->bindParam(':code', $verifyCode, PDO::PARAM_INT);
- $command->execute();
- // Require the bundled autoload file - the path may need to change
- // based on where you downloaded and unzipped the SDK
- require __DIR__ . '/Twilio/autoload.php';
- // Use the REST API Client to make requests to the Twilio REST API
- $client = new Client($twilioSid, $twilioToken);
- // Use the client to do fun stuff like send text messages!
- $client->messages->create(
- // the number you'd like to send the message to
- '+1$phone',
- array(
- // A Twilio phone number you purchased at twilio.com/console
- 'from' => '+16746746746',
- // the body of the text message you'd like to send
- 'body' => "Welcome to Bit, your temporary PIN code is: $verifyCode"
- )
- );
- echo '<p>A verification code was sent to your phone number. Please enter it below.</p>';
- /*** close the database connection ***/
- $dbh = null;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement