Home  >  Article  >  Backend Development  >  php soap usage

php soap usage

WBOY
WBOYOriginal
2016-08-08 09:27:321686browse

Preparation:

Be prepared before using soap. Create a file in the www directory and add the following content under the file.

<?php echo phpinfo();?>
run this file to see if there is a soap module. If not, open the php.ini file. , remove the ; in front of
extension=php_soap.dll

, and restart apache.

Client:

Create a new php file in the www directory, the file name is client.php, add the following content under the file

<?php 
	$client = new SoapClient(null, array(&#39;location&#39; => "http://www.samples.com/Service.php",//服务端的文件位置
                                     'uri'=> "","login" => "outsider","password" => "1234567"//访问服务端文件时的用户名和密码));
	$user_info = json_decode($client->user_info());//服务端的方法
	$result = $client->show(1,3);//服务端的方法
	print_r($user_info->email.".....".$result);

?>
Server:

Create a new php file in the www directory, the file name Service.php, add the following content under this file

<?php
if (!isset($_SERVER[&#39;PHP_AUTH_USER&#39;]) || !isset($_SERVER[&#39;PHP_AUTH_PW&#39;]) ||
        !($_SERVER[&#39;PHP_AUTH_USER&#39;] == &#39;outsider&#39; && $_SERVER[&#39;PHP_AUTH_PW&#39;] == &#39;1234567&#39;)) {
    header(&#39;WWW-Authenticate: Basic realm="WEBSERVICE"&#39;);
    header("HTTP/1.0 401 Unauthorized");
    echo "You must enter a valid login ID and password to access this resource/n";
    die;
}//验证用户名和密码
class fuck{
function show($one, $two) {
        return $one + $two;
    }
 
    function user_info() {
        $user_info = array(
            &#39;name&#39; => 'Outsider',
            'sex' => '男',
            'email' => 'outsider@outsiderla.me',
            'tel' => '1369*******',
        );
        return json_encode($user_info);
    }
}
$server = new SoapServer(null, array('uri' => '', 'location' => 'http://www.samples.com/soapService.php'));
$server->setClass('fuck');//注册fuck类
$server->handle();
?>
. This way, the server and client are finished. Now access the client. The result is
outsider@outsiderla.me....4

The above introduces the usage of php soap, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:nginx phases introductionNext article:nginx phases introduction