如果他们直接访问,直接PHP文件错误消息


Direct PHP file error message if they access it directly

我有一个名为"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;
?>

只需在脚本开头添加一个复选框:

if(empty($_GET['channel']))
    die('ERROR: Please put a stream user in your link. ex: http://konvictgaming.com/status.php?channel=konvictgaming');