0
我在玩SOAP和PHP。但我無法弄清楚爲什麼返回的對象似乎不保留實例。首先,讓我告訴你的示例代碼,然後我會解釋:PHP5 SOAP:如何保持實例?
client.php:
$client = new SoapClient("http://myhost/remote.wsdl");
try {
if($client->login("root","toor")) {
echo $client->getTotal()."\n";
}
} catch (SoapFault $exception) {
echo $exception;
}
server.php:
class Remote {
private $auth = false;
public function login($user, $pass) {
if($user == "root" && $pass == "toor") {
$this->auth = true;
return true;
} else throw new SoapFault("Server","Access Denied to '$user'.");
}
public function getTotal() {
if($this->auth) {
return rand(1000,9999);
} else throw new SoapFault("Server","Error: Not Authorized.");
}
}
$server = new SoapServer("remote.wsdl");
$server->setClass("Remote");
$server->handle();
我能「登錄「,所以從$ client-> login返回的值是true。 但是,當我打電話給$ client-> getTotal,$ this-> auth是false(並因此引發錯誤)。
爲了保持之前設置的值,我需要做些什麼?
在此先感謝...