-4

我有一个名为“Status.php”的 php 文件,基本上允许该人使用正确的 URL

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

1 回答 1

2

只需在脚本开头添加一个检查:

if(empty($_GET['channel']))
    die('ERROR: Please put a stream user in your link. ex: http://konvictgaming.com/status.php?channel=konvictgaming');
于 2013-07-15T12:33:11.443 回答