Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class server
- {
- private $status;
- function getServerStatus()
- {
- $url = 'http://world.needforspeed.com/SpeedAPI/ws/game/1.0/nfsw/server/status?output=json';
- //cURL
- $shehrozs = curl_init();
- curl_setopt($shehrozs, CURLOPT_URL, $url);
- curl_setopt($shehrozs, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); // user agent
- curl_setopt($shehrozs, CURLOPT_TIMEOUT, 10); // Таймаут запроса
- curl_setopt($shehrozs, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($shehrozs);
- # Если твой сервер не поддерживает cURL, используй file_get_contents
- // if(!$response = file_get_contents($url)) return;
- $response = json_decode($response);
- return $response->worldServerStatus->status;
- }
- }
- $nfsko = new server();
- $result = $nfsko->getServerStatus();
- if('UP' == $result)
- {
- echo "Сервера Need for Speed World запущены!";
- }
- else if('DOWN' == $result)
- {
- echo "Сервера Need for Speed World выключены";
- }
- else
- {
- echo "Не могу прочитать статус";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement