[PHP] Re: Connect Active Directory using LDAP... please help :)

2003-07-03 Thread Vince C
Hi Sven,

I have tried to put the my login username in that place. But it showed
"Invalid Credental". Since I am new to this AD and LDAP, would it be the
format of my username? Should I just put my login username, or should I put
the whole bunch of line such as "CN=my name, DN=" something like this? I
really confuse the login format of this and so does "objectClass" stuff for
filter. Could you give me an idea? Do you know any web site that talk about
this ? Thank you very much!

Vince

"Sven" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hi vince,
>
> Vince C wrote:
> >  > $ldaphost= "company.com";
> >
> > if(!($ldap = ldap_connect($ldaphost,389))){
> >  die("ldap server cannot be reached");
> > } else {
> >  $oudc = " dc=company, dc=com";
> >  $dn2 = "";
> >  $password = "";
>
> did you define your user and password? afaik win ad isn't searchable by
> anonymous.
> ciao SVEN
>
> >  echo "Connected and ready to bind...";
> >  if (!($res = @ldap_bind($ldap, $dn2, $password))) {
> >   print(ldap_error($ldap) . "");
> >   die ("Could not bind the $dn2");
> >   echo "Couldn't bind ";
> >  } else {
> >   echo "Binded and Ready to search";
> >   echo "LDAP = $ldap";
> >   echo "oudc = $oudc";
> >
> >  //
> >  $filter="(&(objectClass=user)(objectCategory=person)(|(sn=sorg)))";
> >   $filter= "sn=*"; $sr=ldap_search($ldap,$oudc,$filter);
> >   echo "number of entries found: " . ldap_count_entries($ldap,
> > $sr) . "";
> >   echo "filter = $filter";
> >   echo "sr=$sr";
> >
> >   if (!$sr) {
> >die("search failed\n");
> >   } else {
> >echo " Searched and ready for get entries.";
> >$info= ldap_get_entries($ldap, $sr);
> >
> >for ($i=0; $i<$info["count"]; $i++) {
> > print ("");
> > print ("" . $info[$i]["cn"][0] . " " .
> > $info[$i]["sn"][0] . "");
> > print ("" . $info[$i]["mail"][0] . "");
> > print ("");
> > print "In the display FOR loop";
> >}
> >echo " After loop.";
> >   }
> >  }
> >  ldap_unbind($ldap);
> >  echo "LDAP unbinded";
> > }
>
>



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



[PHP] Connect Active Directory using LDAP... please help :)

2003-07-02 Thread Vince C
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:




 Brand New Checking..  




AD Test


Connected and ready to bind...";
 if (!($res = @ldap_bind($ldap, $dn2, $password))) {
  print(ldap_error($ldap) . "");
  die ("Could not bind the $dn2");
  echo "Couldn't bind ";
 } else {
  echo "Binded and Ready to search";
  echo "LDAP = $ldap";
  echo "oudc = $oudc";

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

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

   for ($i=0; $i<$info["count"]; $i++) {
print ("");
print ("" . $info[$i]["cn"][0] . " " . $info[$i]["sn"][0]
. "");
print ("" . $info[$i]["mail"][0] . "");
print ("");
print "In the display FOR loop";
   }
   echo " After loop.";
  }
 }
 ldap_unbind($ldap);
 echo "LDAP unbinded";
}

?>





Thanks in advance!  Vince



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