Hello,
I am trying to connect to my windows 2003 AD server and pull information of all the users to create a phone list with php. This script connects and can grab some attributes but not everything. Anyone have an Idea why I can get the Phone Number and some other things.
<?php
/*
LDAP Import
-----------
name
phone
cell
fax
office
location
*/
$name = "ldap_user";
$pass = "ldap_password";
$adServer = "ldap_server";
$ldapconn = ldap_connect($adServer) or die("Could not connect to LDAP server.");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0) or die ("Could not set option referrals");
$account = $name;
$password = $pass;
$ldaprdn = $account."@company.com";
$ldappass = $password;
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass) or die("Couldn't bind to AD!");
}
$dn = "ou=users,dc=compnay,dc=corp";
$filter="(|(sn=*)(sAMAccountName=".$account."))";
$justthese = array("displayname", "mail", "company", "department", "physicalDeliveryOfficeName", "mobile", "ipPhone", "telephoneNumber");
$sr=ldap_search($ldapconn, $dn, $filter, $justthese);
$info = ldap_get_entries($ldapconn, $sr);
for ($i=0; $i < $info["count"]; $i++) {
echo "Name: ".$info[$i]["displayname"][0]."<br>";
echo "Email: ".$info[$i]["mail"][0]."<br>";
echo "Company: ".$info[$i]["company"][0]."<br>";
echo "Department: ".$info[$i]["department"][0]."<br>";
echo "Location: ".$info[$i]["physicalDeliveryOfficeName"][0]."<br>";
echo "Cell Phone: ".$info[$i]["mobile"][0]."<br>";
echo "Internal Phone: ".$info[$i]["ipPhone"][0]."<br>";
echo "Office Phone: ".$info[$i]["telephoneNumber"][0]."<br>";
echo "<hr>";
}
ldap_free_result($sr);
ldap_unbind($ldapconn);
?>
output:
Name: User1
Email: user1@company.com
Company: company1
Department: Information Technology
Location:
Cell Phone: 555-555-5555
Internal Phone:
Office Phone:
as you can see in the output not everything gets grabed