Reply to Re: -> LDAP question <-

Your name:

Reply:


Posted by Geoffrey on 01/11/07 16:11

Hi Steve --

After you successfully bind to your LDAP server using the procedure you
outline below, there is no need to conduct a second search to retrieve
information about the user. What you're looking for already exists (or
should, theoretically) in $entries. It's simply a matter of accessing
the data in the array. Notice that when you're performing the bind
operation, you're using $entries[0]['dn'] -- the other attributes for
the user are in the same array. So if you want to retrieve a user's
last name, for example, you would access it here: $entries[0]['sn'].

Just to be on the safe side, perhaps doing a simple print_r($entries)
might be a good first step to ensuring that the data you're looking for
is actually there.

I hope this helps. :)


Geoffrey


Steve JORDI wrote:
> Hi,
> I'm checking a user identity on a secure LDAP server using the
> following code:
>
> $ldapconn = ldap_connect("ldaps://myserver.mycompany.ch", 636 )
> or die( "Can't connect to LDAP" ) ;
>
> $ldapresult = ldap_search( $ldapconn,"o=mycompany,c=ch","cn=".$name);
>
> if( $ldapresult ) {
> $entries = ldap_get_entries( $ldapconn, $ldapresult ) ;
> if( $entries["count"] ) {
> $ldapbind = ldap_bind( $ldapconn, $entries[0]['dn'], $pwd ) ;
> if( $ldapbind ) {
> echo "Connected: user exists, password checked<br>" ;
> }
> }
>
> This works ok if I submit the right $name and $pwd
>
> Then I'd like to retrieve some data from the specified user, say
> the givenName and sn but can't figure out a way to retrieve those
> values using ldap_read or ldap_get_values
>
> For example:
> $results = ldap_read($ldapconn, "cn=myname,o=mycompany,c=ch",
> '(objectclass=person)', array( "givenname", "sn" ) ) ;
> $firstname = ldap_get_values($ldapconn, $results, "givenname" ) ;
> $lastname = ldap_get_values($ldapconn, $results, "sn" ) ;
>
> This fails on the ldap_get_values() stating that the supplied resource
> is not a valid ldap result entry resource.
>
>
> If I use something like:
>
> $firstname = ldap_get_values($ldapconn, $ldapresult, "givenname" ) ;
> $lastname = ldap_get_values($ldapconn, $ldapresult, "sn" ) ;
>
> It fails too...
>
> What is wrong?
> Thanks for any help.
>
>
> Sincerely,
> Steve JORDI
>
> (Remove the K_I_L_LSPAM from my email address)
> ------------------------------------------------
> 1197 Prangins Email: stevejordiK_I_L_LSPAM@hotmail.com
> Switzerland WWW: www.sjordi.com
> ------------------------------------------------
> Volcanoes at www.sjordi.com/volcanoes
> MovieDB at www.sjmoviedb.com
> ------------------------------------------------

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация