Advertisement
Guest User

Untitled

a guest
Aug 10th, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. class server
  4. {
  5.     private $status;
  6.    
  7.     function getServerStatus()
  8.     {
  9.         $url = 'http://world.needforspeed.com/SpeedAPI/ws/game/1.0/nfsw/server/status?output=json';
  10.        
  11.         //cURL
  12.         $shehrozs = curl_init();
  13.         curl_setopt($shehrozs, CURLOPT_URL, $url);
  14.         curl_setopt($shehrozs, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); // user agent
  15.         curl_setopt($shehrozs, CURLOPT_TIMEOUT, 10); // Таймаут запроса  
  16.         curl_setopt($shehrozs, CURLOPT_RETURNTRANSFER, true);
  17.         $response = curl_exec($shehrozs);
  18.        
  19.         # Если твой сервер не поддерживает cURL, используй file_get_contents
  20.         // if(!$response = file_get_contents($url)) return;
  21.        
  22.         $response = json_decode($response);
  23.         return $response->worldServerStatus->status;
  24.     }
  25. }
  26.  
  27.  
  28. $nfsko = new server();
  29. $result = $nfsko->getServerStatus();
  30. if('UP' == $result)
  31. {
  32.     echo "Сервера Need for Speed World запущены!";
  33. }
  34. else if('DOWN' == $result)
  35. {
  36.     echo "Сервера Need for Speed World выключены";
  37. }
  38. else
  39. {
  40.     echo "Не могу прочитать статус";
  41. }
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement