正在检查SOAP中请求的脚本url


Checking requesting script url in SOAP

我有非常基本的SOAP服务器:

$soap = new SoapServer(null, array('uri' => ''));
$soap->addFunction('myFunction');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $soap->handle();
} else {
    echo "Available functions:";
    foreach ($soap->getFunctions() as $func) {
        echo "'n't" . $func;
    }
}

现在,我有一组特定的域(我拥有),我期望从中请求,而不是其他域——比如说,在数组中:

$allowed_domains = array('http://www.example.com', 'http://www.otherexample.com');

我如何创建一个"白名单",因为只有那些域才能真正向这个soap服务器脚本发出请求(任何其他域都将被拒绝访问)?

谢谢!

检查如下:

if(!in_array($_SERVER['HTTP_REFERER'], $allowed_domains) {
    // operation is denied
    exit 0;
}

希望有帮助:)