如何在类PHP中使用Request


How to use Request in Class PHP

我试图从web调用请求,但无法工作,此代码从网站调用命令游戏服务器。

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;
}

我的错误:

遇到PHP错误

严重性:通知

消息:未定义索引:命令

文件名:include/SampRcon.php

行号:7

您可以重写以下行:

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

像这样的东西:

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

这样它就不会给你带来错误。

您所犯的错误在GET请求时找不到命令pram。首先检查您的服务配置是否正常。

 <?php
$rcon = new SampRconAPI('server_ip', server_port, 'server_rcon_pass'); 
$rcon->Call('name ' . $playerid_here);

print_r( $rcon->getInfo());

http://forum.sa-mp.com/showthread.php?t=104299

这是一个例子https://gist.github.com/Westie/234209?>