Click to See Complete Forum and Search --> : ldap and php with w2k active directory


Anon
04-16-2002, 10:51 AM
I am trying to get ldap info from a W2K active directory. I have the authentication down, but I want to search on the aa0000000 to get the name associated with the login. Basically I am making a request form that will be used once a year, but need to be sure of the people signing up, use resources already setup, and have one login/pass.

Thanks for any help,
Kurt


Connect and autentication(works):
if (!($ldap = ldap_connect("x.x.x.x"))) {
die ("Could not connect to LDAP server");
}
$dn = "aa0000000@my.domain.edu";
$password = "pass";
if (!($res = @ldap_bind($ldap, $dn, $password))) {
die ("Could not bind to $dn");
}

Search for name(broken):
Error:Warning: Supplied argument is not a valid ldap link resource in /var/www/html/ldap.php on line 36

$person ="aa0000000";
$filter="(|(sn=$person*)(givenname=$person*))";
$justthese = array( "ou", "sn", "givenname", "mail");
$sr=ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
print $info["count"]." entries returned<p>";

Anon
07-23-2002, 05:59 AM
hope this helps u guys!!


$dn = username@mydomain.com;
$password="password";

if (!($res = @ldap_bind($ldap,$dn,$password))) {
echo "wrong username or password";
}else{
$sr=ldap_search($ldap,"cn=users,dc=domain,dc=com","(userprincipalname=$dn)");
$info = ldap_get_entries($ldap, $sr);
for ($i=0; $i<$info["count"]; $i++) {
echo "Display Name: ". $info[$i]["displayname"][0] ."<br>";
echo "Email: ". $info[$i]["mail"][0] ."<p>";
}
}