Connect Active Directory using LDAP... please help :)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone,

I tried to connect to Active Directory (AD) by using php. I heard that it
could use LDAP to achieve it.  I have written some code on my machine
(Win2000) and try to connect to AD.  It looks like the it could connect,
bind, and even search (I determined base on the line I placed).  However, it
return 0 entries.  If I used the same filter and use utilites "lpd.exe" on
Windows 2000 Server (the AD machine).  I could return some entries. I am
hestitating whether do I made some mistake on my program, or something other
than my code.  Does anyone know what the problem is?  Any comment are
welcome!  Thanks!

Vince

P.S. Here is my code:

<HTML>
<HEAD>
<!-- brandcheck.php -->
<TITLE> Brand New Checking..........  </TITLE>
</HEAD>

<BODY>

<p><font size ="4">AD Test</font></p>
<table width ="100%" border="1" cellspacing="0" cellpadding="0">

<?php
$ldaphost= "company.com";

if(!($ldap = ldap_connect($ldaphost,389))){
 die("ldap server cannot be reached");
} else {
 $oudc = " dc=company, dc=com";
 $dn2 = "";
 $password = "";
 echo "<p>Connected and ready to bind...";
 if (!($res = @ldap_bind($ldap, $dn2, $password))) {
  print(ldap_error($ldap) . "<BR>");
  die ("Could not bind the $dn2");
  echo "<p>Couldn't bind ....";
 } else {
  echo "<p>Binded and Ready to search....";
  echo "<br>LDAP = $ldap";
  echo "<br>oudc = $oudc";

 // $filter="(&(objectClass=user)(objectCategory=person)(|(sn=sorg)))";
 $filter= "sn=*";
  $sr=ldap_search($ldap,$oudc,$filter);
  echo "<p>number of entries found: " . ldap_count_entries($ldap, $sr) .
"<p>";
  echo "<br>filter = $filter";
  echo "<br>sr=$sr";

  if (!$sr) {
   die("<p>search failed\n");
  } else {
   echo "<p> Searched and ready for get entries.....";
   $info= ldap_get_entries($ldap, $sr);

   for ($i=0; $i<$info["count"]; $i++) {
    print ("<TR>");
    print ("<TD width=15%>" . $info[$i]["cn"][0] . " " . $info[$i]["sn"][0]
. "</TD>");
    print ("<TD width=85%>" . $info[$i]["mail"][0] . "</TD>");
    print ("</TR>");
    print "<br>In the display FOR loop";
   }
   echo "<br> After loop.....";
  }
 }
 ldap_unbind($ldap);
 echo "<p>LDAP unbinded....";
}

?>
</table>
</BODY>

</HTML>

Thanks in advance!  Vince



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux