Saturday, 15 May 2010

php - LDAP authentication to retrieve users fullname -


{Please help me in giving names to users in ldap authentication given below. Users are successfully authenticating but I could not get full name for users.

  $ ldaphost = 'localhost'; $ Ldapport = 38 9; $ Ds = ldap_connect ($ ldaphost, $ ldapport) or die ("Could not connect to our login server!"); Ldap_set_option ($ ds, LDAP_OPT_PROTOCOL_VERSION, 3); Ldap_set_option ($ ds, LDAP_OPT_REFERRALS, 0); Ldap_set_option (NULL, LDAP_OPT_DEBUG_LEVEL, 7); If ($ DS) {$ upname = 'iap \\' $ username; $ Ldapbind = @ldap_bind ($ ds, $ upname, $ upasswd); If ($ ldapbind) {// PRINT "Congratulations! $ Username is certified. & Lt; BR & gt; & lt; BR & gt;"; Ldap_unbind ($ ds); Back true; } Else {// Print "$ username - access denied! 

return false; }} And {return false; }

}

?>}

< P> You can try this solution
  // -------------------------------- --- ------------------------------------------- // LDAP server Connect with // ------------------------------------------------ ------------------------------ $ ldap_connection = ldap_connect (LDAP_HOSTNAME); If (FALSE === $ ldap_connection) {Dies ("& lt; p & gt; Failed to connect to LDAP server:". LDAP_HOSTNAME. "& Lt; / p & gt;"); } Ldap_set_option ($ ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die ('Unable to set LDAP protocol version'); Ldap_set_option ($ ldap_connection, LDAP_OPT_REFERRALS, 0); // If we need it to search LDAP (right! == ldap_bind ($ ldap_connection, $ ldap_username, $ ldap_password)) (Dead ('> l & gt; & lt; p & gt; Failed to bind to LDAP server. & Lt ; / P & gt; ';);} // -------------------------------------- --------- ------------------------------- // Receive a list of all Active Directory users Do it ----------------------------------------------- - ------------------------------ $ ldap_base_dn = 'DC = xyz, DC = local'; $ Search_filter = "(and (Object category = person)) "; $ result = ldap_search ($ ldap_connection, $ ldap_base_dn, $ search_filter); if (wrong! == $ result) {$ entries = ldap_get_entrie S ($ ldap_connection, $ result); if ($ entries ['count']> gt; 0) {$ odd = 0; foreign currency ($ entries [0] AS key = & gt; $ value) {if (0 === $ strange% 2) {$ ldap_columns [] = $ key;} $ strange ++;} echo & lt; table class = "data" & gt; 'resonance' & lt; tr & gt; '; $ Header_count = 0; Foreign currency ($ ldap_columns as $ col_name) {if (0 === $ header_ count ++) {echo '& lt; Th class = "ul" & gt; '; } And if (calculation ($ ldap_columns) === $ header_count) {echo '& lt; Th class = "ur" & gt; '; } Else {echo '& lt; Th class = "u" & gt; '; } Echo $ Col_name '& Lt; / Th> '; } Echo & lt; / Tr & gt; '; ($ I = 0; $ i & lt; $ entries ['count']; $ i ++) {echo ' '; } If (isset ($ entries [$ i] [$ col_name])) {$ output = NULL; If ('lastlogon' === $ col_name || 'lastlogontimestamp' === $ col_name) {$ Output = Date ('DM D, Y @ H: I: S', ($ entries [$ i] [$ col_name ]] [0] / 10000000) - 11676009600); } And {$ Output = $ entries [$ i] [$ col_name] [0]; } $ Output echo. '& Lt; / Td> '; }} Echo & lt; / Tr & gt; '; } Echo '& lt; / Table & gt; '; }} Ldap_unbind ($ lda  

No comments:

Post a Comment