Copy CodeThe code is as follows:
Class Myframework_soap_server extends Zend_soap_server {
protected $_login = ";
protected $_password = ";
Public function __construct ($wsdl = null, array $options = null) {
Parent::__construct ($wsdl, $options);
if (Isset ($options [' login ')]) {
$this->_login= $options [' Login '];
$this->_password= $options [' Password '];
$this->_authenticate ();
}
}
Private Function _authenticate () {
$this->setauthenticate ($this->_login, $this->_password);
}
Public Function Sethttplogin ($login) {
$this->_login= $login;
}
Public Function Sethttppassword ($password) {
$this->_password= $password;
if (Isset ($this->_login)) {
$this->_authenticate ();
}
}
Public Function Setauthenticate ($login, $password) {
if ($_server[' php_auth_user ']!= $login | | $_server[' PHP_AUTH_PW ']!= $password) {
Header (' Www-authenticate:basic realm= ' myframework realm ');
Header (' http/1.0 401 Unauthorized ');
echo "You must enter a valid login ID and password to access this resource.\n";
Exit
}
}
}
?>
Copy CodeThe code is as follows:
Class Soap_server_test {
Public $view = ';
Public $params = ';
Public $requestObj = ';
Public $dbObj = ';
function __construct () {
$this->view = $GLOBALS [' View '];
$this->params = $GLOBALS [' params '];
$this->requestobj = $GLOBALS [' Requestobj '];
$this->dbobj = $GLOBALS [' Dbobj '];
}
function Indexaction () {
if (Isset ($_get[' WSDL '))) {
$autodiscover = new Myframework_soap_autodiscover ();
$autodiscover->setclass (' model_service_soapclasssettest ');
$autodiscover->handle ();
Exit
} else {
$options = Array (' encoding ' = ' UTF-8 ', ' login ' = ' tangjian ', ' password ' = ' 123456 ');
$options = Array (' encoding ' = ' UTF-8 ');
$soap = new Myframework_soap_server ("http://tj.MyFramework.com/default/soap_server_test/index?wsdl", $options);
$soap->sethttplogin (' Tangjian ');
$soap->sethttppassword (' 123456 ');
$soap->setclass (' model_service_soapclasssettest ');
$soap->handle ();
Exit
}
}
function Clientaction () {
$options = Array (' encoding ' = ' UTF-8 ', ' login ' = ' tangjian ', ' password ' = ' 123456 ',
' Compression ' =>soap_compression_gzip);
$options = Array (' encoding ' = ' UTF-8 ',
' Compression ' =>soap_compression_gzip);
$client = new Myframework_soap_client (' http://tj.MyFramework.com/default/soap_server_test/index?wsdl ', $options);
$client->sethttplogin (' Tangjian ');
$client->sethttppassword (' 123456 ');
$result = $client->getpass (' Tang ', "man");
Print_r ($result);
}
}
?>
http://www.bkjia.com/PHPjc/322857.html www.bkjia.com true http://www.bkjia.com/PHPjc/322857.html techarticle Copy the code as follows: PHP class Myframework_soap_server extends Zend_soap_server {protected $_login = '; protected $_password = ''; Public function __construct ($wsdl = null ...