2013-07-15 24 views
-4

我有一個名爲「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; 

?> 
+0

請在這裏發表的代碼,而不是在引擎收錄。 –

+0

我試了好幾次,它拒絕讓我給我4縮進的消息 –

+1

'if(!isset($ _ GET ['channel']))'anyone? – deceze

回答

2

只需在腳本的開頭添加一個檢查:

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

工作謝謝! –

+0

[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)將不勝感激,如果它解決了你:) – jterry

+1

會做伴侶,只是等待爲定時器倒計時xD! –