Code of a PHP SoapServer instance

Source: Internet
Author: User
Tags soap

PHP SoapServer instance code
Server code:

The code is as follows: Copy code

<? Php
 
If (! Isset ($ _ SERVER ['php _ AUTH_USER ']) |! Isset ($ _ SERVER ['php _ AUTH_PW ']) |
! ($ _ SERVER ['php _ AUTH_USER '] = 'outsider' & $ _ SERVER ['php _ AUTH_PW'] = '2016 ')){
Header ('www-Authenticate: Basic realm = "WEBSERVICE "');
Header ("HTTP/1.0 401 Unauthorized ");
Echo "You must enter a valid login ID and password to access this resource/n ";
Die;
}
 
Class test {
 
Function show ($ one, $ two ){
Return $ one + $ two;
    }
 
Function user_info (){
$ User_info = array (
'Name' => 'outsider ',
'Sex' => 'male ',
'Email '=> 'outsider @ outsiderla. Me ',
'Tel '=> '2017 *******',
);
Return json_encode ($ user_info );
    }
 
}
$ Server = new SoapServer (null, array ('uri '=> 'Server. Php', 'location' => 'http: // demo.test.com/server.php '));
$ Server-> setClass ('test ');
// $ Server-> addFunction ('getuserinfo ');
$ Server-> handle ();
?>

Third-party call code:

The code is as follows: Copy code

<? Php
$ Soap = new SoapClient (null, array ('location' => 'http: // demo.test.com/server.php', 'uris '=> 'Server. php', "login" => "outsider", "password" => "123456 "));
$ User_info = json_decode ($ soap-> user_info ());
Echo $ user_info-> email;
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.