note 28062 deleted from ref.ldap by victor

From: Date: Wed, 01 Jan 2003 13:35:45 +0000
Subject: note 28062 deleted from ref.ldap by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-41538@lists.php.net to get a copy of this message
Hi. I am having a little trouble getting results from Active Directory using LDAP and PHP. Below are the results that my script returns every time it is run. It seems like is is connecting and binding with no problem: Connecting ...connect result is Resource id #1 Binding ...Bind result is 1 Searching for (sn=S*) ... Warning: LDAP: Unable to perform the search: Can't contact LDAP server in c:\inetpub\wwwroot\ldap.php on line 20 Search result is Warning: ldap_count_entries(): supplied argument is not a valid ldap result resource in c:\inetpub\wwwroot\ldap.php on line 23 Number of entires returned is Getting entries ... Warning: ldap_get_entries(): supplied argument is not a valid ldap result resource in c:\inetpub\wwwroot\ldap.php on line 26 Data for items returned: Closing connection And here is my code (edited the example above): <?php // basic sequence with LDAP is connect, bind, search, interpret search // result, close connection echo "<h3>LDAP query test</h3>"; echo "Connecting ..."; $ds=ldap_connect("NYCMADC"); // must be a valid LDAP server! $user = "CORP\\username"; $password = "*******"; echo "connect result is ".$ds.""; if ($ds) { echo "Binding ..."; $r=ldap_bind($ds, $user, $password); // this is an "anonymous" bind, typically // read-only access echo "Bind result is ".$r.""; echo "Searching for (sn=S*) ..."; // Search surname entry $sr=ldap_search($ds, "dc=pbwan, dc=com", "sn=S*"); 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] .""; } echo "Closing connection"; ldap_close($ds); } else { echo "<h4>Unable to connect to LDAP server</h4>"; } ?> I would appreciate any help anyone can offer. Thanks. :)

« previous php.notes (#41538) next »