Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //ini_set('display_errors','On');
- //error_reporting('E_ALL');
- header('Content-Type: text/html; charset=utf-8');
- $tmi_key = 'tmi_key';
- if (isset($_GET['channel']) && !empty($_GET['channel'])) {
- $channel = $_GET['channel'];
- } else {
- echo 'Введите название канала.';
- return;
- }
- if (!preg_match('/^[a-zA-Z0-9_]{5,25}$/', $_GET['channel'])) {
- echo 'Ошибка, попытка ввести неправильные данные.';
- return;
- }
- $uptime = file_get_contents("https://crashmax.ru/twitch/uptimetest.php?channel=$channel");
- $url = sprintf('https://api.twitch.tv/kraken/streams/%s', $channel);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Client-ID: '.$tmi_key]);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
- curl_setopt($ch, CURLOPT_URL, $url);
- $response = json_decode(curl_exec($ch), true);
- //var_dump($response);
- if ($response['stream'] != NULL) {
- echo $response['stream']['channel']['display_name'], ' стримит ', $response['stream']['game'];
- echo ' Title: ',$response['stream']['channel']['status'];
- echo ' Viewers: ',$response['stream']['viewers'];
- echo ' Uptime: ',$uptime;
- } else {
- echo $channel,' не в сети.';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement