php - PHP5 SOAP : how to keep an instance? -
i'm playing around soap , php. can't figure out why returned object seems not keep instance. let me show first example code , explain:
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 '$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();
i'm able "login" returned value $client->login true. but, when call $client->gettotal, $this->auth false (and error raised).
what need in order keep value set previously?
thank in advance...
ok! solution here:
http://www.php.net/manual/en/soapserver.setpersistence.php
this result:
session_start(); //important $server = new soapserver("remote.wsdl"); $server->setclass("remote"); $server->setpersistence(soap_persistence_session); $server->handle();
and that's it!
Comments
Post a Comment