Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  2. <script type="text/javascript">
  3. $(document).ready(function(){
  4. $("#phone").submit(function()
  5. {
  6. var phone_no = $('#phone_no').val();
  7.  
  8. if(phone_no != '')
  9. {
  10.  
  11. $.post("sendcode.php", { phone_no: phone_no },
  12. function(data)
  13. {
  14. $(".result").html(data);
  15. },
  16. "html"
  17. );
  18.  
  19. }
  20.  
  21. return false;
  22. });
  23. });
  24. </script>
  25.  
  26. <div class = "result"></div>
  27. <p>Enter your phone number below, and we will send you a verification code to that phone number.</p>
  28. <form id = "phone" method = "POST" action = "">
  29. <label for = "phone">Phone number</label>
  30. <input name = "phone" type = "text" id = "phone_no" />
  31. <input name = "submit" type = "submit" value = "Send Verification Code" />
  32. </form>
  33.  
  34. <p>Enter Verification Code received to the phone number specified above in the form below.</p>
  35.  
  36. <form id = "verification" method = "POST" action = "verify.php">
  37. <label for = "code">Verification Code</label>
  38. <input name = "code" type = "text" id = "code" />
  39. <input name = "submit" type = "submit" value = "Verify" />
  40. </form>
  41.  
  42. <?php
  43. if(isset($_POST['code']))
  44. {
  45. $verifyCode = $_POST['code'];
  46.  
  47. /*** mysql hostname ***/
  48. $hostname = 'localhost';
  49. /*** database name ***/
  50. $dbname = 'sms';
  51. /*** mysql username ***/
  52. $username = 'root';
  53. /*** mysql password ***/
  54. $password = 'secret';
  55.  
  56. try {
  57.  
  58. $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  59.  
  60. // USER_ID is the login ID of the user
  61. $sql = "SELECT code FROM user WHERE id = {$user_id}";
  62. $sth = $dbh->query($sql);
  63.  
  64. $code = $sth->fetchColumn();
  65.  
  66. if($code == $verifyCode)
  67. {
  68. echo "Your account has been validated.";
  69.  
  70. // verify user in db
  71. $todo = "UPDATE user SET status = 1 WHERE user_id = {$user_id}";
  72. $dbh->execute($todo);
  73.  
  74. }
  75. else
  76. {
  77. echo "Your account has not been validated.";
  78. }
  79.  
  80. $dbh = null;
  81. }
  82. catch(PDOException $e)
  83. {
  84. echo $e->getMessage();
  85. }
  86. }
  87. ?>
  88.  
  89. <?php
  90. // configuration
  91. use TwilioRestClient;
  92.  
  93. /*** mysql hostname ***/
  94. $hostname = 'localhost';
  95. // database name
  96. $dbname = 'sms';
  97. /*** mysql username ***/
  98. $username = 'root';
  99. /*** mysql password ***/
  100. $password = 'secret';
  101. // enter SID here
  102. $twilioSid = 'ACxxx';
  103. // enter twilio token here
  104. $twilioToken = 'TKxxx';
  105. if(isset($_POST['phone_no']))
  106. {
  107. try
  108. {
  109. $verifyCode = rand(1000, 9999);
  110.  
  111. $phone = $_POST['phone_no'];
  112.  
  113. $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  114.  
  115. /*** add verification code and phone number to db **/
  116. $sth = "INSERT INTO user (phone, code) VALUES(:phone, :code)";
  117. $command = $dbh->prepare($sth);
  118. $command->bindParam(':phone', $phone, PDO::PARAM_STR);
  119. $command->bindParam(':code', $verifyCode, PDO::PARAM_INT);
  120. $command->execute();
  121.  
  122. // Require the bundled autoload file - the path may need to change
  123. // based on where you downloaded and unzipped the SDK
  124. require __DIR__ . '/Twilio/autoload.php';
  125.  
  126. // Use the REST API Client to make requests to the Twilio REST API
  127.  
  128. $client = new Client($twilioSid, $twilioToken);
  129.  
  130. // Use the client to do fun stuff like send text messages!
  131. $client->messages->create(
  132. // the number you'd like to send the message to
  133. '+16476476476',
  134. array(
  135. // A Twilio phone number you purchased at twilio.com/console
  136. 'from' => '+16746746746',
  137. // the body of the text message you'd like to send
  138. 'body' => "Welcome to Bit, your temporary PIN code is: $verifyCode"
  139. )
  140. );
  141.  
  142. echo '<p>A verification code was sent to your phone number. Please enter it below.</p>';
  143.  
  144. /*** close the database connection ***/
  145. $dbh = null;
  146. }
  147. catch(PDOException $e)
  148. {
  149. echo $e->getMessage();
  150. }
  151. }
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement