Guest User

Untitled

a guest
Nov 25th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. require_once '../../wp-config.php';
  5.  
  6. $config = json_decode(file_get_contents('dynmap_config.json'), true);
  7. $msginterval = $config['webchat-interval'];
  8.  
  9. if (is_user_logged_in()) {
  10.  
  11. echo "true";
  12.  
  13. $user = wp_get_current_user();
  14.  
  15. if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] < time()) {
  16. $micro = explode(' ', microtime());
  17. $timestamp = $micro[1].round($micro[0]*1000);
  18.  
  19. $data = json_decode(trim(file_get_contents('php://input')));
  20.  
  21. if ($data->message != "") {
  22.  
  23. $data->name = $user->display_name;
  24. $data->timestamp = $timestamp;
  25. $old_messages = json_decode(file_get_contents('dynmap_webchat.json'), true);
  26. if (!empty($old_messages)) {
  27. foreach($old_messages as $message) {
  28. if (($timestamp - $config['updaterate'] - 10000) < $message['timestamp']) {
  29. $new_messages[] = $message;
  30. }
  31. }
  32. }
  33. $new_messages[] = $data;
  34. file_put_contents('dynmap_webchat.json', json_encode($new_messages));
  35. $_SESSION['lastchat'] = time()+$msginterval;
  36. }
  37.  
  38. $_SESSION['lastchat'] = time()+$msginterval;
  39. }
  40. else if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] > time()) {
  41. header('HTTP/1.1 403 Forbidden');
  42. }
  43.  
  44. } else {
  45.  
  46. echo "false";
  47.  
  48. }
  49. ?>
Add Comment
Please, Sign In to add comment