tcpwrap_check

(PECL tcpwrap >= 0.1.0)

tcpwrap_check — tcpwrap のチェックを実行する

説明

function tcpwrap_check(
    string $daemon,
    string $address,
    string $user = ?,
    bool $nodns = false
): bool

この関数は /etc/hosts.allow および /etc/hosts.deny の内容をもとに、あるクライアントが daemon サービスへのアクセスを許可されているか 否かを調べます。

パラメータ

daemon

サービスの名前。

address

クライアントのリモートアドレス。IP アドレスあるいはドメイン名の どちらでも指定可能。

user

ユーザー名(オプション)。

nodns

address がドメイン名の場合、それを IP アドレスに名前解決するために DNS が使用されます。 nodns を true に指定すると、この処理を 禁止します。

戻り値

アクセスが許可されている場合に true 、それ以外の場合に false を返します。

例

例1 ローカルホストからの全接続を拒否する

/etc/hosts.deny ファイルに以下の行が含まれており、

php: 127.0.0.1

以下のようなコードを実行する

<?php
if (!tcpwrap_check('php', $_SERVER['REMOTE_ADDR'])) {
  die('You are not welcome here');
}
?>

参考

詳細な情報は、hosts_access(3) の man ページを参照ください。

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top