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

2003-07-07 Thread The.Rock
Try this and see if it works. I had the same problem until I did a little
reading. I had to use [EMAIL PROTECTED] as username then I didn't get
the credential errors anymore.

hope this helps, its very basic but hopefully it gets you started.

* Config.php**
?php

 //LDAP connection parameters array
 $ldapcfg = array();

 //Set default LDAP port
 //The default is 389, don't change unless you know
 //absolutely that its different.
 $ldapcfg[port] = 389;

 //Set LDAP servername to connect to
 $ldapcfg[server] = 'server_name';

 //Set ldap username for binding to server
 $ldapcfg[username] = [EMAIL PROTECTED];

 //Set password for username
 $ldapcfg[password] = password;

 //Set base DN to search the whole domain
 $ldapcfg[basedn] ='dc=Domain_name, dc=com';

?

**index.php
?php

 include('config.php');

// specify the LDAP server to connect to
$conn = ldap_connect($ldapcfg[server]) or die(Could not connect to
server);

// bind to the LDAP server specified above
$bind = ldap_bind($conn,$ldapcfg[username],$ldapcfg[password]);

 if(!$bind)
 {
 echo ldap_error($conn);
 exit;
 }

//There is a optional fourth parameter, that can be added to
//restrict the attributes and values returned by the server
//to just those required when searching.
$params = array(mail, cn, sn);

// list all entries from the base DN
$result = ldap_list($conn, $ldapcfg[basedn], cn=*);
 if ($result)
 {
  // Lets get the entries from our results
  $info = ldap_get_entries($conn, $result);
  echo p.$info[count].entries returned/p;
  // and print attribute values
  for ($i=0; $i$info[count]; $i++)
  {
  echo table;
  echo tr;
  echo td.$info[$i][cn][0]./td;
  echo td.$info[$i][sn][0]./td;
  echo /tr;
  echo /table;
  }
 }


// all done? then close the connection...
ldap_close($conn);

?



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



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

2003-07-03 Thread sven
hi vince,

Vince C wrote:
 ?php
 $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 pConnected and ready to bind...;
  if (!($res = @ldap_bind($ldap, $dn2, $password))) {
   print(ldap_error($ldap) . BR);
   die (Could not bind the $dn2);
   echo pCouldn't bind ;
  } else {
   echo pBinded and Ready to search;
   echo brLDAP = $ldap;
   echo broudc = $oudc;

  //
  $filter=((objectClass=user)(objectCategory=person)(|(sn=sorg)));
   $filter= sn=*; $sr=ldap_search($ldap,$oudc,$filter);
   echo pnumber of entries found:  . ldap_count_entries($ldap,
 $sr) . p;
   echo brfilter = $filter;
   echo brsr=$sr;

   if (!$sr) {
die(psearch 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 brIn the display FOR loop;
}
echo br After loop.;
   }
  }
  ldap_unbind($ldap);
  echo pLDAP unbinded;
 }



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



[PHP-DB] 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:
  ?php
  $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 pConnected and ready to bind...;
   if (!($res = @ldap_bind($ldap, $dn2, $password))) {
print(ldap_error($ldap) . BR);
die (Could not bind the $dn2);
echo pCouldn't bind ;
   } else {
echo pBinded and Ready to search;
echo brLDAP = $ldap;
echo broudc = $oudc;
 
   //
   $filter=((objectClass=user)(objectCategory=person)(|(sn=sorg)));
$filter= sn=*; $sr=ldap_search($ldap,$oudc,$filter);
echo pnumber of entries found:  . ldap_count_entries($ldap,
  $sr) . p;
echo brfilter = $filter;
echo brsr=$sr;
 
if (!$sr) {
 die(psearch 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 brIn the display FOR loop;
 }
 echo br After loop.;
}
   }
   ldap_unbind($ldap);
   echo pLDAP unbinded;
  }





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