Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. //ini_set('display_errors','On');
  3. //error_reporting('E_ALL');
  4. header('Content-Type: text/html; charset=utf-8');
  5. $tmi_key = 'tmi_key';
  6. if (isset($_GET['channel']) && !empty($_GET['channel'])) {
  7.     $channel = $_GET['channel'];
  8. } else {
  9.     echo 'Введите название канала.';
  10.     return;
  11. }
  12. if (!preg_match('/^[a-zA-Z0-9_]{5,25}$/', $_GET['channel'])) {
  13.     echo 'Ошибка, попытка ввести неправильные данные.';
  14.     return;
  15. }
  16. $uptime = file_get_contents("https://crashmax.ru/twitch/uptimetest.php?channel=$channel");
  17. $url = sprintf('https://api.twitch.tv/kraken/streams/%s', $channel);
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_HTTPHEADER, ['Client-ID: '.$tmi_key]);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
  21. curl_setopt($ch, CURLOPT_URL, $url);
  22. $response = json_decode(curl_exec($ch), true);
  23. //var_dump($response);
  24. if ($response['stream'] != NULL) {
  25.     echo $response['stream']['channel']['display_name'], ' стримит ', $response['stream']['game'];
  26.     echo ' Title: ',$response['stream']['channel']['status'];
  27.     echo ' Viewers: ',$response['stream']['viewers'];
  28.     echo ' Uptime: ',$uptime;
  29. } else {
  30.     echo $channel,' не в сети.';
  31. }
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement