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