複製碼程式碼如下:
class MyFramework_Soap_server extends Zend_Soap_Server
class MyFramework_Soap_server extends Zend_Soap_Server
class MyFramework_Soap_server extends Zend_Soap_Server
受保護的$_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();
}
}
解剖函數_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_AUTH_USER']!=$login || $_SERVER['PHP_AUTH_PW']!=$||密碼) {
header('WWW-Authenticate: Basic Realm="MyFramework Realm"');
header('HTTP/1.0 401 尚未授權');
echo "您必須輸入有效的登入 ID 和密碼才能存取此資源。n";
退出;
}
}
}
? :
class Soap_server_test { 公用$View=''; 公有$params = ''; public $requestObj = '';
public $dbObj = '';function __construct() {
$this->view = $GLOBALS['view'];
$this->params = $GLOBALS['params'];
$this->requestObj = $GLOBALS['requestObj'];
$this->dbObj = $GLOBALS['dbObj'];
}
函數indexAction(){
if(isset($_GET['wsdl'])) {
$autodiscover = new MyFramework_Soap_AutoDiscover();
$autodiscover->setClass('Model_Service_SoapClassSetTest');
$autodiscover->handle();
退出;
} else {
//$opti =>; 'UTF-8','登入'=>'tangjian','密碼'=>'123456');
$opti =>; '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();
退出;
}
}
function clientAction() {
//$opti =>; 'UTF-8','login'=>'tangjian','password'=>'123456',
// '壓縮'=>SOAP_COMPRESSION_GZIP);
$opti =>; 'UTF-8',
'壓縮' =>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($結果);
}
}
?
以上就介紹了php程式碼重新封裝zend_soap實作http連線安全認證的php程式碼,包含了php程式碼的內容,希望對PHP教學有興趣的朋友有幫助。