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;
?>

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.