Advertisement
nicatronTg

Untitled

Aug 22nd, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $config =  json_decode(file_get_contents('dynmap_config.json'), true);
  5. $msginterval = $config['webchat-interval'];
  6.  
  7. if($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] < time())
  8. {
  9.     $micro = explode(' ', microtime());
  10.     $timestamp = $micro[1].round($micro[0]*1000);
  11.    
  12.     $data = json_decode(trim(file_get_contents('php://input')));
  13.     $data->timestamp = $timestamp;
  14.     $old_messages = json_decode(file_get_contents('dynmap_webchat.json'), true);
  15.     if(!empty($old_messages))
  16.     {
  17.         foreach($old_messages as $message)
  18.         {
  19.             if(($timestamp - $config['updaterate'] - 10000) < $message['timestamp'])
  20.                 $new_messages[] = $message;
  21.         }
  22.     }
  23.     $new_messages[] = $data;
  24.     file_put_contents('dynmap_webchat.json', json_encode($new_messages));
  25.     $_SESSION['lastchat'] = time()+$msginterval;
  26. }
  27. elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $_SESSION['lastchat'] > time())
  28. {
  29.     header('HTTP/1.1 403 Forbidden');
  30. }
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement