php webservice soapheader 身份验证

什么不说直接上代码

soapserver.php

item[0]->value; //$pwd =$value->item[1]->value; if($value->username == 'admin'&& $value ->password=='123456') { $this->Authenticated = true; } else { $this->Authenticated = FALSE; } } function feline(){ if($this->Authenticated){ return '成功'; } else { return '下次成功'; } } } $server = new SoapServer(null, array('uri' => 'http://test.cheshi.com')); $server->setClass('mysoapclass'); $server->handle(); ?>

soapclient.php

username = $username; $this->password = $password; } } try { $auth = new authentication_header('admin', '123456'); $authvalues = new SoapVar($auth, SOAP_ENC_OBJECT, 'authenticate','http://test.cheshi.com'); //$authvalues =array('username'=>'admin','pwd'=>'123456'); $header = new SoapHeader('http://test.cheshi.com/', 'authenticate', $authvalues,true); //$client = new SoapClient('http://test.cheshi.com/webservice/soapserver.php?wsdl'); $client = new SoapClient(null, array('uri' => 'http://test.cheshi.com', 'location' => 'http://test.cheshi.com/webservice/soapserver.php', 'trace' => true)); $re=$client->__setSoapHeaders(array($header)); echo $result =$client->__soapCall('feline',array()); }catch (SoapFault $e){ echo $e->getMessage(); } ?>

你可能感兴趣的:(PHP,webservice,php,authentication,header,function,soap)