php - Retrieve full name from ldap AD -



php - Retrieve full name from ldap AD -

this ldap code authenticate user. have show users total name 1 time user had logged in. how total name of user ad?

<?php function ldapchecklogin ($username, $upasswd) { $ldaphost = '10.20.30.40'; $ldapport = 389; $ds = ldap_connect($ldaphost, $ldapport) or die("could not connect 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) { //$username = 'na\'; //ok - congratulations! na\spups authenticated. $upname = 'iap\\' . $username; $ldapbind = @ldap_bind($ds, $upname, $upasswd); if ($ldapbind) { //print "congratulations! $username authenticated.<br><br>"; ldap_unbind( $ds ); homecoming true; } else { //print "$username - access denied!<br><br>"; homecoming false; } } else { homecoming false; } } ?>

you need retrieve user's entry using ldap_search user's samaccountname e.g. (samaccountname=$username) or userprincipalname e.g. (userprincipalname=$username . "@" . $domain.com ) filter attribute.

samaccountname unique in domain whereas userprincipalname unique across entire forest.

when perform ldap_search need include cn or displayname in attributes return.

if search successful need process resulting entry , extract cn and/or displayname.

php active-directory ldap

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -