2016-03-24 29 views
0

我試圖從網絡調用請求但不工作,此代碼從網站調用命令遊戲服務器。如何在類中使用請求PHP

class SampRconAPI 
{ 

private $command; 

public function __construct() 
{ 
    $this->command = $_REQUEST["command"]; 
} 

if($this->command == "cmdlist") 
{ 
    $aCommands = $this->packetSend('cmdlist'); 
    unset($aCommands[0]); 

    foreach($aCommands as &$sCommand) 
    { 
     $sCommand = trim($sCommand); 
    } 

    return $aCommands; 
} 

我的錯誤:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: command

Filename: include/SampRcon.php

Line Number: 7

+1

如果你想訪問由GET/POST傳遞比你可以用$ _REQUEST來獲取值數據。 –

+0

是的,但我從我的網站呼叫請求它不起作用。它顯示錯誤 –

+0

你如何創建這個類的對象? –

回答

0

您可以改寫以下行:

$this->command = $_REQUEST["command"]; 

是這樣的:

$this->command = isset($_REQUEST["command"]) ? $_REQUEST["command"] : ""; 

因此,它不會給你錯誤。