Lightweight Directory Access Protocol
Le protocole d'annuaire.
Au cas où ça me botterait un jour d'avoir une DB centralisée…
Faire un petit annuaire LDAP pour moi hébergé sur mon serveur :)
Je me lance avec ce tutoriel: addressbook
<?php // Test ldap connection. $ldap_host='ldap.example.com'; $ldap_basedn='dc=example,dc=com'; $ldap_use_start_tls=false; $ldap_binddn=''; $ldap_bindpw=''; ini_set('html_errors','off'); header('Content-Type: text/plain'); echo "LDAP query test\n"; echo "Connecting ...\n"; $ds=ldap_connect($ldap_host); // must be a valid LDAP server! echo "connect result is " . $ds . "\n"; if ($ds) { if (ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { echo "Using LDAPv3\n"; } else { echo "Failed to set protocol version to 3\n"; } if ($ldap_use_start_tls) { echo "Enabling StartTLS\n"; echo "Result is "; var_dump(ldap_start_tls($ds]]; } echo "Binding"; if ($ldap_binddn!='') { echo " with authenticated bind ...\n"; $r = ldap_bind($ds,$ldap_binddn,$ldap_bindpw); } else { echo " with anonymous bind ...\n"; $r=ldap_bind($ds); } echo "Bind result is " . $r . "\n"; echo "Searching for (cn=*) ...\n"; // Search surname entry $sr=ldap_search($ds, $ldap_basedn, "cn=*"); echo "Search result is " . $sr . "\n"; echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "\n"; echo "Getting entries ...\n"; $info = ldap_get_entries($ds, $sr); echo "Data for " . $info["count"] . " items returned:\n"; for ($i=0; $i<$info["count"]; $i++) { echo "dn is: " . $info[$i]["dn"] . "\n"; echo "first cn entry is: " . $info[$i]["cn"][0] . "\n"; echo "first email entry is: " . $info[$i]["mail"][0] . "\n------\n"; } echo "Closing connection\n"; ldap_close($ds); } else { echo "Unable to connect to LDAP server\n"; } ?>
( source attachment test-ldap.php tout en bas)