内部 LAN のみで実行され、ネットワーク上のすべての Windows マシンが SBS または本格的な Windows Active Directory に対して認証される場合、LDAP クエリを使用してページを閲覧しているユーザーのログインをクエリできます。私はこれを何年も前にイントラネットで行いました。非常に信頼性が高いですが、Windows ドメインに対して認証された内部ユーザーに対してのみ機能します。
基本 LDAP クエリ
<?php
// basic sequence with LDAP is connect, bind, search, interpret search result,
// close connection
$ds=ldap_connect("192.168.0.1"); // ! Your LDAP/Active Direcotry Server !
echo "Connection: ".$ds."";
if ($ds) {
echo "Binding ..";
$r=ldap_bind($ds); // this is an "anonymous" bind, typically read-only access
echo "Bind result is ".$r."";
echo "Searching for (sn=A*) .."; // this example searches surname entry for all surnames starting with A
$sr=ldap_search($ds,"o=Organisation Name, c=UK", "sn=A*"); // ! must use real base dn here !
echo "Search result is ".$sr."";
echo "Number of entires returned is ".ldap_count_entries($ds,$sr)."";
echo "Getting entries ...";
$info = ldap_get_entries($ds, $sr);
echo "Data for ".$info["count"]." items returned:";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: ". $info[$i]["dn"] ."";
echo "first cn entry is: ". $info[$i]["cn"][0] ."";
echo "first email entry is: ". $info[$i]["mail"][0] ."";
}
//now close connection
ldap_close($ds);
} else {
echo "Unable to connect to LDAP server";
}
?>