Code of a PHPSoapServer instance-PHP source code

Source: Internet
Author: User
This article will introduce you to the code of a PHPSoapServer instance. I hope this instance will be helpful to you. This article will introduce you to the code of a PHP SoapServer instance. I hope this instance will be helpful to you.

Script ec (2); script

PHP SoapServer instance code
Server code:

The Code is as follows:


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:

$ 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.