NuSOAP 기본 인증 적용

NuSOAP에 기본 인증 적용
NuSOAP + HTTP 기본 인증

1 사전 작업[ | ]

2 nusoap-server-auth.php[ | ]

<?php
require_once 'vendor/nusoap/lib/nusoap.php';

function is_auth() {
	if(!isset($_SERVER['PHP_AUTH_USER'])) return false;
	if(!isset($_SERVER['PHP_AUTH_PW'])) return false;
	if($_SERVER['PHP_AUTH_USER'] != 'jmnote') return false;
	if($_SERVER['PHP_AUTH_PW'] != 'P@ssw0rd') return false;
	return true;
}

function sayAnnyeong($name) {
	if( !is_auth() ) return;
	return "안녕, $name!";
}

$server = new nusoap_server();
$server->soap_defencoding = 'UTF-8';

$server->configureWSDL('Welcome');
$server->register("sayAnnyeong",
	array('name' => 'xsd:string'),
	array('return' => 'xsd:string'));

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

3 nusoap-client-auth.php[ | ]

<?php
require_once 'vendor/nusoap/lib/nusoap.php';

$client = new nusoap_client('http://zetawiki.com/ex/soap/nusoap-server-auth.php?wsdl');
$client->decode_utf8 = false;

$client->setCredentials('jmnote','P@ssw0rd','basic');
$result = $client->call('sayAnnyeong', array('name'=>'John Smith'));
print_r($result);
// 안녕, John Smith!
→ 기본 인증 아이디/패스워드가 맞지 않으면 SOAP 서비스 이용 불가.

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}