PHP 8.3.4 Released!

ldap_exop

(PHP 7 >= 7.2.0, PHP 8)

ldap_exop拡張されたオペレーションを実行する

説明

ldap_exop(
    LDAP\Connection $ldap,
    string $request_oid,
    string $request_data = null,
    array $controls = null,
    string &$response_data = ?,
    string &$response_oid = ?
): mixed

指定された ldap で オペレーションの OID を request_oid で指定し、 データを request_data で指定して拡張されたオペレーションを実行します。

パラメータ

ldap

ldap_connect() が返す LDAP\Connection クラスのインスタンス。

request_oid

拡張オペレーションリクエストのOID。 LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN のいずれか、 または送信したい操作のOIDを示す文字列。

request_data

拡張オペレーションリクエストのデータ。 LDAP_EXOP_WHO_AM_I のように、 操作によってはNULLで問題ない場合もありますし、 BERエンコードが必要な場合もあります。

controls

リクエストと一緒に送信する LDAP コントロール の配列

response_data

この値を指定すると、拡張オペレーションレスポンスの値で埋められます。 指定しなかった場合に後でこのデータを取得するには、 結果オブジェクトに対して ldap_parse_exop を使います。

response_oid

この値を指定すると、レスポンスのOIDで埋められます。 これは通常、リクエストのOIDと等しい値です。

戻り値

response_data を指定した場合、成功時に true を返し、エラー時に false を返します。 response_data を指定しなかった場合、結果識別子を返し、 エラー時に false を返します。

変更履歴

バージョン 説明
8.1.0 引数 ldap は、LDAP\Connection クラスのインスタンスを期待するようになりました。 これより前のバージョンでは、有効な ldap link リソース を期待していました。
7.3.0 serverctrls のサポートが追加されました。

例1 Whoami 拡張オペレーション

<?php
$ds
= ldap_connect("localhost"); // assuming the LDAP server is on this host

if ($ds) {
// bind with appropriate dn to give update access
$bind = ldap_bind($ds, "cn=root, o=My Company, c=US", "secret");
if (!
$bind) {
echo
"Unable to bind to LDAP server";
exit;
}

// Call WHOAMI EXOP
$r = ldap_exop($ds, LDAP_EXOP_WHO_AM_I);

// Parse the result object
ldap_parse_exop($ds, $r, $retdata);
// Output: string(31) "dn:cn=root, o=My Company, c=US"
var_dump($retdata);

// Same thing using $response_data parameter
$success = ldap_exop($ds, LDAP_EXOP_WHO_AM_I, NULL, NULL, $retdata, $retoid);
if (
$success) {
var_dump($retdata);
}

ldap_close($ds);
} else {
echo
"Unable to connect to LDAP server";
}
?>

参考

add a note

User Contributed Notes 1 note

up
-1
Roland Gruber
5 years ago
The following can be used to run the refresh command in PHP 7.2 as ldap_exop_refresh comes with 7.3.

$dn= 'cn=user,dc=test,dc=org';
$ttl = 3600;
$data = '';
$data .= '80' . sprintf("%'.02x", strlen($dn)) . bin2hex($dn);
$data .= '81' . sprintf("%'.02x", 4) . sprintf("%'.08x", $ttl);
$data = hex2bin('30' . sprintf("%'.02x", strlen($data)/2) . $data);
$success = ldap_exop($ldapHandle, LDAP_EXOP_REFRESH, $data);
To Top