Ben,

I was trying the same thing, but I am not sure you are using the same setup as me. My office runs a windows 2000 domain with a Exchange server 2000 box. All profile information is stored in the windows 2000 domain controller, and the exchange server accesses the information from there. So it doesnt use its own LDAP. And to make it all the more interesting, this script is running on our Intranet, on a FreeBSD 5 box with the OpenLDAP client.

The following script will bring back all the fields available in LDAP, as long as they are filled out. In this script you need to have a valid <DOMAIN_USER> and a valid <DOMAIN_PASS>. There are ways to do this anonymously, you just need to change the $ldap_bind line to remove the $ldaprdn and $ldappass.

To change the search criteria, you can change the "$filter" variable, at the moment it filters on the domain user's userid, or "samaccountname".

At the bottom of this post, I have included search results based on my user, I have removed everything except the fields you might want.

<?
$ldapuser = "<DOMAIN_USER>";
$ldappass = "<DOMAIN_PASS>";

$ldaprdn  = 'DOMAIN\\'.$ldapuser;
$ldapconn = @ldap_connect("dns.domain.com", 3268);
@ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) {
    $ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass);
}

$base_dn = "DC=dns,DC=domain,DC=com";
$filter="samaccountname=$ldapuser";
$read = ldap_search($ldapconn, $base_dn, $filter);

$info = ldap_get_entries($ldapconn, $read);
$ii=0;
for ($i=0; $ii<$info[$i]["count"]; $ii++){
    $data = $info[$i][$ii];
    echo $data.":&nbsp;&nbsp;".$info[$i][$data][0]."<br>";
}
?>

Hope it helps

Phil Dowson

Ben Crothers wrote:
Hoping this is an easy question to answer, apologise upfront if this is so
basic, but just been put in charge of a PHP app with LDAP interface to M$
Exchange, and trying to figure out how it works.

At the moment it works fine and extracts fields like first- and surname,
title, department, etc. I need to add the 'office' field, and added it at
the end of this filter line:

---------------------------------------------------
     $filter =
"(|(sn=$search[$i]*)(givenname=$search[$i]*)(title=$search[$i]*)(department=
$search[$i]*)(office=$search[$i]*))";
----------------------------------------------------

...but so far it's not working. I *know* there's data in the 'office'
field -- any ideas as to what I'm missing?

Thanks a lot in advance,

Ben

---------------- ---Field List--- ---------------- homemdb: manager: memberof: altrecipientbl: publicdelegatesbl: streetaddress: info: cn: company: c: department: description: displayname: mail: facsimiletelephonenumber: givenname: initials: instancetype: legacyexchangedn: l: distinguishedname: objectcategory: objectclass: objectguid: objectsid: homephone: mobile: pager: physicaldeliveryofficename: postofficebox: postalcode: primarygroupid: proxyaddresses: name: samaccountname: samaccounttype: showinaddressbook: st: sn: telephonenumber: co: textencodedoraddress: title: useraccountcontrol: userprincipalname: usnchanged: usncreated: whenchanged: whencreated: wwwhomepage: mailnickname: msexchuseraccountcontrol: deliverandredirect: homemta: msexchhomeservername: msexchmailboxguid: msexchmailboxsecuritydescriptor: mdbusedefaults: protocolsettings:

----------------
---Field List---
----------------

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



Reply via email to