我有一個名爲「Status.php」一個PHP文件,該文件基本上允許的人,如果他們使用了正確的URL直接PHP文件中的錯誤信息,如果他們直接
http://konvictgaming.com/status.php?channel=isypie
網上拉他們twitch.tv流/離線訪問狀態,完美的作品
但是我想它,這樣,如果他們試圖訪問status.php文件直接 http://konvictgaming.com/status.php 它會返回錯誤
錯誤:請放流用戶在您的鏈接。 例如:http://konvictgaming.com/status.php?channel=konvictgaming
我當前的代碼
<?php
$channelName = htmlspecialchars($_GET['channel'], ENT_QUOTES);
$clientId = ''; // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png'; // Set online image here
$offline = 'offline.png'; // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);
header("Content-Type: image/png");
$image = null;
if ($json_array['stream'] != NULL) {
$channelTitle = $json_array['stream']['channel']['display_name'];
$streamTitle = $json_array['stream']['channel']['status'];
$currentGame = $json_array['stream']['channel']['game'];
$image = file_get_contents($online);
} else {
$image = file_get_contents($offline);
}
echo $image;
?>
請在這裏發表的代碼,而不是在引擎收錄。 –
我試了好幾次,它拒絕讓我給我4縮進的消息 –
'if(!isset($ _ GET ['channel']))'anyone? – deceze