Zend_soap PHP Code _php Tutorial for Implementing secure authentication of HTTP connections

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.