When I first saw this I thought you were just trying to check a single channel, so I made this updated snippet… It uses cURL and v5 for checks but can be modified for any case.
<?php
function file_get_contents_curl($url) {
$curlHeader = array(
"Client-ID: xxxxxxxxxxxxxxxxxxxxxxxx", /* SET CLIENT ID HERE */
"Accept: application/vnd.twitchtv.v5+json"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function Login2ID($user) {
$L2ID = json_decode(@file_get_contents_curl('https://api.twitch.tv/kraken/users?api_version=5&login=' . $user), true);
$UserID = $L2ID['users']['0']['_id'];
return $UserID;
}
$channelName = 'matt_thomas'; /* SET TWITCH NAME HERE */
$channelID = Login2ID($channelName);
$dataArray = json_decode(file_get_contents_curl('https://api.twitch.tv/kraken/streams?channel=' . $channelID), true);
if ($dataArray['streams']['0']['_id'] != null) {
echo "Online";
}
else {
echo "Offline";
}
?>
Of course you can work in the channel array and implode to use multiple channels.