1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
<!-----------------Page menu.php ------------------------------------>
<?php
session_start();
echo $_SESSION['username';]
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
// config
$ldapserver = 'ldap://XXXX.XXX.XXX.XXX';
$ldapuser= $_SESSION["username"];
$ldappass = '*********';
$ldaptree = "DC=croix-rouge,DC=asso,dc=fr";
// connect
$ldapconn = ldap_connect($ldapserver) or die("Could not connect to LDAP server.");
echo $ldapconn;
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn)); //L'erreur est ici !!!!!!!!!!!!
// verify binding
if ($ldapbind) {
echo "LDAP bind successful...<br /><br />";
$result = ldap_search($ldapconn,$ldaptree, "(cn=mesbahiy)") or die ("Error in search query: ".ldap_error($ldapconn));
$data = ldap_get_entries($ldapconn, $result);
// iterate over array and print data for each entry
// echo '<h1>Show me the users</h1>';
for ($i=0; $i<$data["count"]; $i++) {
//echo "dn is: ". $data[$i]["dn"] ."<br />";
$users=$data[$i]["cn"][0]; //nom complet = common name
echo "User: ". $users ."<br />";
$nom=$data[$i]["sn"][0]; //nom = surname
echo "Nom: ". $nom ."<br />";
$prenom=$data[$i]["givenname"][0]; //prénom = givenname
echo "Prénom: ". $prenom ."<br />";
if(isset($data[$i]["mail"][0])) { //mail
$email=$data[$i]["mail"][0];
echo "Email: ". $email ."<br /><br />";
} else {
echo "Email: None<br /><br />";
}
}
// print number of entries found
echo "Number of entries found: " . ldap_count_entries($ldapconn, $result);
} else {
echo "LDAP bind failed...";
}
}
echo "hello je récupère l'email de Adam : ".$email;
// all done? clean up
ldap_close($ldapconn);
?> |
Partager