Ldap Snip

كتابات: 

ini_set('display_errors', 'On');
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldapuser = "COMPANY@testuser1";
$ldappassword = "";
$ldapserver = "x.x.x.x";
$ldapport = '389';

// connect to ldap server $ldapconn = ldap_connect($ldapserver, $ldapport) or die("Could not connect to $ldapserver");

// check if ldap_connect returned a resource value if($ldapconn) echo "$ldapconn";

echo "Ldap connection debug: " . ldap_error($ldapconn) . "\n"; $ldapConn = $ldapconn; ldap_set_option($ldapConn,LDAP_OPT_PROTOCOL_VERSION,3); ldap_set_option($ldapConn,LDAP_OPT_REFERRALS,0); $ldapBind = ldap_bind($ldapConn, 'test@COMPANY', 'PASSWORD');

$ldap_base_dn = "OU=COMPANY,DC=local"; $attributes = array(); $attributes[] = 'givenname'; $attributes[] = 'mail'; $attributes[] = 'samaccountname'; $attributes[] = 'sn'; //$result = ldap_search($ldapConn,$ldap_base_dn, "(&(objectCategory=person)(samaccountname=))", $attributes) or die ("Error in search query: ".ldap_error($ldapconn)); $filter="(samaccountname=)"; // this command requires some filter

$sr=ldap_read($ldapConn, $ldap_base_dn, $filter, $attributes); $data = ldap_get_entries($ldapConn, $sr);

//$data = ldap_get_entries($ldapconn, $result); echo "


Number of entries found: " . ldap_count_entries($ldapconn, $sr); print '
';

// iterate over array and print data for each entry echo '

Show me the users

'; for ($i=0; $i<$data["count"]; $i++) { //echo "dn is: ". $data[$i]["dn"] ."
"; echo "User: ". $data[$i]["cn"][0] ."
"; if(isset($data[$i]["mail"][0])) { echo "Email: ". $data[$i]["mail"][0] ."

"; } else { echo "Email: None

"; } }

print_r($data);

exit;

فضلاً إذا أعجبتك هذه الصفحة لاتنسى أن تقوم بمشاركتها