Sure. Thanks in advance.
--------- my code --------------
<?php
// I want to search the name containing the string "chan"
$name = "chan";
$ldap_server = "ldap://192.168.xxx.xxx"; //domain controller
$auth_user = "user@microsoft.com"; // take an example of microsoft.com, I substitute this with my domain name
$auth_pass = "xxxx"; // user password
// Set the base dn to search the entire microsoft.com directory.
$base_dn = "DC=microsoft, DC=com";
/ filter the search for all people in the microsoft.com tree that have a name that matches any one of the following attributes name, displayname, or cn. /
$filter = "(&(objectClass=user)(objectCategory=person)
(|(name=$name)(displayname=$name)(cn=$name*)))";
// connect to server
if (!($connect=ldap_connect($ldap))) {
die("Could not connect to ldap server");
echo "Could not connect to ldap server";
}
// check if return a valid connection id
echo "\$connect is $connect<BR>\n";
if (ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3))
echo "Using LDAPv3<BR>\n";
else
echo "Failed to set protocol version to 3<BR>\n";
// bind to server
if (!($bind=ldap_bind($connect, $auth_user, $auth_pass))) {
die("Unable to bind to server");
echo "Unable to bind to server";
}
// search active directory
if (!($search=ldap_search($connect, $base_dn, $filter))) {
die("Unable to search ldap server");
echo "Unable to search ldap server";
}
$number_returned = ldap_count_entries($connect,$search);
$info = ldap_get_entries($connect, $search);
echo "The number of entries returned is ". $number_returned;
for ($i=0; $i<$info["count"]; $i++) {
echo "Name is: ". $info[$i]["name"];
echo "Display name is: ". $info[$i]["displayname"][0];
echo "Email is: ". $info[$i]["mail"][0];
echo "Telephone number is: ". $info[$i]["telephonenumber"][0];
}
?>
--------- end my code --------------
It can print out the resource id $connect after ldap_connect()
It failed at the line of ldap_bind(), with returned error:
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in line xx.
I also tried the tool ldapweb available at http://ldapweb.sourceforge.net/
It failed with the same error.
How can I trace out the reason? Any option I need to configure on the win 2000 server (primary domain controller)?
Thanks again.
Regards,
Raymond