Active Directory

From: Date: Mon, 17 Jun 2002 19:50:46 +0000
Subject: Active Directory
Groups: php.general 
Request: Send a blank email to php-general+get-102581@lists.php.net to get a copy of this message
Hey *, Does anyone have any links on how to work with Active Directory and PHP? I am able to connect but cannot get any queries to work. With ASP I can just open up a ADO recordset object with an LDAP string like: LDAP://myserver/CN=Joe X Blow,OU=653,OU=company,OU=Employees,DC=mysite,DC=company,DC=com With PHP I have been able to Authenticate with this: function AuthUser($username, $pass) { $ds = ldap_connect("myserver"); // must be a valid LDAP server! if ($ds) { $dn = "CN=$username,OU=users,OU=RSC,DC=mycompany,DC=com"; $password = "$pass"; $r = @ldap_bind($ds, $dn, $password ); if ($r) { return True; } else { return False; } } else { return False; } } However, I cannot run a query to get attributes like this: echo "Connecting ...<br>"; $ds = ldap_connect("mysite"); if ($ds) echo "&nbsp;&nbsp;&nbsp;&nbsp;ldap_connect = True<br>\n"; else die("&nbsp;&nbsp;&nbsp;&nbsp;ldap_connect= False<br>\n"); if ($ds) { echo "Binding ...<br>"; $dn = "CN=James Drabb,OU=users,OU=RSC,DC=mysite,DC=com"; $password = "password"; $r = ldap_bind($ds, $dn, $password ); if ($r) echo "&nbsp;&nbsp;&nbsp;&nbsp;ldap_bind = True<br>\n"; else die("&nbsp;&nbsp;&nbsp;&nbsp;ldap_bind = False<br>\n"); echo "Searching ...<br>"; // Search $filter = "(&(objectClass=user)(objectCategory=person)(samAccountName=AXE11125653))"; //$filter = "objectClass=user, objectCategory=person, samAccountName=AXE11125653, dc=mydish,dc=darden,dc=com"; $justthese = array( ); $sr=ldap_search($ds, $filter, $justthese); if ($sr) { $info = ldap_get_entries($ds, $sr); print $info["count"]." entries returned<p>"; } else { echo "ldap_search = FALSE<br>"; } echo "Closing connection...<br>"; $ret = ldap_unbind($ds); if ($ret) echo "&nbsp;&nbsp;&nbsp;&nbsp;ldap_unbind = True<br>\n"; else die("&nbsp;&nbsp;&nbsp;&nbsp;ldap_unbind= False<br>\n"); } else { echo "<h4>Unable to connect to LDAP server</h4>"; } Any help or tips on connecting to Active Directory would be great! Thanks, Jim Drabb -- ------------------------------------------------------------- Never ask a geek why, just nod your head and slowly back away ------------------------------------------------------------- James Drabb JR Programmer Analyst Darden Restaurants Business Systems JDrabb@Darden.com JDrabb@cfl.rr.com

« previous php.general (#102581) next »