I'm trying to extract information from our OpenLDAP server. I am able to extract the "cn", "street", "st" and "mail". I also want to extract the "postalCode" and "telephoneNumber", but I am unable to. Here is my code:
PHP Code:
<?php
if (($ldap_con = ldap_connect("server.domain.com")) != false)
{
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
if (ldap_bind($ldap_con, 'uid=ldapuser,cn=users,dc=server,dc=domain,dc=com', 'password'))
{
$ldap_usr = ldap_search($ldap_con, 'dc=server,dc=domain,dc=com', "(uid=*)");
if ($ldap_usr != false)
{
$ldap_user_data = ldap_get_entries($ldap_con, $ldap_usr);
for ( $i = 0 ; $i < $ldap_user_data["count"] ; $i++ )
{
echo "Name: ".$ldap_user_data[$i]["cn"][0] . "<br>";
echo "Email Address: ".$ldap_user_data[$i]["mail"][0]."<br>";
echo "Street: ".$ldap_user_data[$i]["street"][0]."<br>";
echo "City: ".$ldap_user_data[$i]["l"][0]." State: ".$ldap_user_data[$i]["st"][0]." Zip Code: ".$ldap_user_data[$i]["postalCode"][0]."<br>";
echo "Telephone Number: ".$ldap_user_data[$i]["telephoneNumber"][0]."<br>";
}
}
else
{
echo "ldap_search failed";
}
}
}
else
{
echo "ldap_bind failed with".ldap_error($ldap_con);
}
ldap_unbind($ldap_conn);
?>
My results look like:
Code:
Name: Jane Doe
Email Address: jdoe@domain.com
Street: 123 Street St.
City: Anywhere State: MI Zip Code:
Telephone Number:
As you can see, I am unable to extract data into the Telephone Number and Zip Code fields. If I use an LDAP browser to look at the LDAP server I see that information exists in those fields, but I cant extract it for some reason. Any ideas?