Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. ```
  2. <?php
  3. require_once('../bimadb.php');
  4.  
  5. function RandomString()
  6. {
  7. $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  8. $randstring = '';
  9. for ($i = 0; $i < 6; $i++) {
  10. $randstring = $randstring.$characters[rand(0, strlen($characters))];
  11. }
  12. return $randstring;
  13. }
  14.  
  15. $sql = "SELECT * FROM aktif";
  16. $result = $conn->query($sql);
  17.  
  18. if ($result->num_rows > 0) {
  19. // output data of each row
  20. while($row = $result->fetch_assoc()) {
  21. $tokentime = $row['tokentime'];
  22. $token = $row['token'];
  23. }
  24. } else {
  25. }
  26.  
  27. $token_updated = date("Y-m-d H:i",time());
  28.  
  29. $to_time = strtotime($token_updated);
  30. $from_time = strtotime($tokentime);
  31. $minutes = round(abs($to_time - $from_time) / 60,2);
  32.  
  33. if ($minutes>15) {
  34. $token = RandomString();
  35.  
  36. $sql = "UPDATE `aktif` SET `token` = '".$token."',`tokentime` = '".$token_updated."'";
  37. $stmt = $conn->prepare($sql);
  38. $stmt->execute();
  39. $stmt->close();
  40.  
  41. $token_updated = date("d-m-Y H:i",time());
  42. echo $token . ' - Updated : '. $token_updated .' - Interval : 15 menit';
  43. } else {
  44. echo $token . ' - Updated : '. date("d-m-Y H:i",strtotime($tokentime)) .' - Interval : 15 menit';
  45. }
  46. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement