Непонимаю почему скрипт возвращает ошибку: Error: No such attribute :?: PHP: $dn = "cn=VIA, cn=Users, dc=mykolaiv, dc=obu"; Составлял смотря в adsiedit.msc Подскажите где нетак? PHP: <?php $domain1 = "gorod"; $domain2 = "dk"; $domain_name = "$domain1.$domain2"; // Имя домена $ldap_user = "VA@$domain_name"; // username $ldap_pass = "********"; // associated password $ds=ldap_connect($domain_name); // assuming the LDAP server is on this host // Fix for Windows 2003 AD ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ds, LDAP_OPT_REFERRALS, 0); if ($ds) { // bind if(ldap_bind($ds, $ldap_user, $ldap_pass)) { // prepare data $dn = "cn=VIA, cn=Users, dc=mykolaiv, dc=obu"; $value = "*******"; $attr = "password"; // compare value $r=ldap_compare($ds, $dn, $attr, $value); if ($r === -1) { echo "Error: ".ldap_error($ds); } elseif ($r === TRUE) { echo "Password correct."; } elseif ($r === FALSE) { echo "Wrong guess! Password incorrect."; } } else { echo "Unable to bind to LDAP server."; } ldap_close($ds); } else { echo "Unable to connect to LDAP server."; } ?>
Переделал В общем т.к. задача скрипта стояла в проверке авторизации через LDAP на AD Win2003,то выкрутился таким скриптом: PHP: <html> <body> <?php // Изменение кодировки из UTF-8 в Windows-1251 function utf2win($str) { return mb_convert_encoding($str, "WINDOWS-1251", "UTF-8"); }; function arr2list($arr) { $list=""; for ($i = 0; $i < count($arr); $i++) { $list=$list.$arr[$i]; if ($i < count($arr)-1) $list=$list."; "; } return $list; }; $domain_name = "mykolaiv.obu"; // Имя домена $ldap_user="VakulenkoIA"; $ldap_pass=""; $base_dn="dc=mykolaiv, dc=obu"; // Connect to LDAP server $ldap_con = @ldap_connect($domain_name); if ($ldap_con) { // Fix for Windows 2003 AD ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap_con, LDAP_OPT_REFERRALS, 0); // binding to LDAP server $ldap_bind = @ldap_bind($ldap_con, $ldap_user."@".$domain_name, $ldap_pass); if ($ldap_bind) { echo "LDAP bind successful..."; $sr=ldap_search($ldap_con, $base_dn, "sAMAccountName=".$ldap_user); //echo "Number of entires returned is ".ldap_count_entries($ldap_con, $sr); $info = ldap_get_entries($ldap_con, $sr); echo "<br>"; echo "<br>DN: ".utf2win($info[0]["dn"]); echo "<br>sAMAccountName: ".utf2win($ldap_user); echo "<br>mail: ".utf2win(arr2list($info[0]["mail"])); echo "<br>displayName: ".utf2win($info[0]["cn"][0]); echo "<br>memberof: "; for ($i = 0; $i < $info[0]["memberof"]["count"]; $i++) { //echo $info[0]["memberof"][$i]."; "; $group_sr=ldap_search($ldap_con, $base_dn, "distinguishedName=".$info[0]["memberof"][$i]); //echo "Number of entires returned is ".ldap_count_entries($ldap_con, $group_sr); $group_info = ldap_get_entries($ldap_con, $group_sr); echo utf2win($group_info[0]["cn"][0]."; "); } //print_r($info[0]["memberof"]); echo "<br><br>"; //print_r($info[0]); } else { echo "LDAP bind failed..."; } ldap_close($ldap_con); } else { echo "Could not connect to LDAP server $domain_name"; } ?> </body> </html>