LDAP: couldn't connect to LDAP server

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
lpro:ldap:code_php [2016/01/13 09:48]
jbaudry [Suppression]
lpro:ldap:code_php [2016/01/13 10:12] (current)
jbaudry
Line 152: Line 152:
 <code php> <code php>
 function show_a_person2($host,​ $uidPerson, $rootdn, $rootpasswd) { function show_a_person2($host,​ $uidPerson, $rootdn, $rootpasswd) {
- $ds=ldap_connect($host); +        ​$ds=ldap_connect("​localhost"​); 
- ldap_set_option($ds,​ LDAP_OPT_PROTOCOL_VERSION,​ 3); +        ldap_set_option($ds,​ LDAP_OPT_PROTOCOL_VERSION,​ 3); 
- $r=@ldap_bind($ds,​$rootdn,$rootpw); +        $r=@ldap_bind($ds,​"​cn=admin,dc=univ-lehavre,​dc=fr","​azerty"​);
- if($ds && $r) {+
  $sr=ldap_search($ds,​ $uidPerson, "​objectclass=*"​);​  $sr=ldap_search($ds,​ $uidPerson, "​objectclass=*"​);​
  $info = ldap_get_entries($ds,​ $sr);  $info = ldap_get_entries($ds,​ $sr);
 + $i=0;
  if(count($info)>​0) {  if(count($info)>​0) {
  $res["​cn"​] = $info[$i]["​cn"​][0];​  $res["​cn"​] = $info[$i]["​cn"​][0];​
- $res["​gecos"​] = $info[$i]["​gecos"​][0];​ 
  $res["​gidnumber"​] = $info[$i]["​gidnumber"​][0];​  $res["​gidnumber"​] = $info[$i]["​gidnumber"​][0];​
  $res["​homedirectory"​] = $info[$i]["​homedirectory"​][0];​  $res["​homedirectory"​] = $info[$i]["​homedirectory"​][0];​
Line 169: Line 168:
  }  }
  return $res ;  return $res ;
- } 
- else { 
- return "​Erreur de connexion"​ ; 
- } 
 } }
 +
 +$profil = show_a_person2("​localhost",​ "​uid=gaetan,​ou=users,​dc=univ-lehavre,​dc=fr",​ "​cn=admin,​dc=univ-lehavre,​dc=fr",​ "​azerty"​) ;
 +
 +echo "<​table border=1>"​ ;
 +foreach($profil as $k=>$v) {
 + echo "<​tr><​td>"​.$k."</​td><​td>"​.$v."</​td></​tr>"​ ;
 +}
 +echo "</​table>";​
 </​code>​ </​code>​