Manuel PHP

ldap_bind

(PHP 4, PHP 5)

ldap_bindAuthentification au serveur LDAP

Description

bool ldap_bind ( resource $link_identifier [, string $bind_rdn [, string $bind_password ]] )

Authentification au serveur LDAP avec le RDN et le mot de passe spécifiés.

Liste de paramètres

link_identifier

Un identifiant de lien LDAP, retourné par la fonction ldap_connect().

bind_rdn

bind_password

Si bind_rdn et bind_password ne sont pas spécifiés, un authentification anonyme est essayé.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Exemples

Exemple #1 Authentification avec LDAP

  1. <?php
  2.  
  3. // Eléments d'authentification LDAP
  4. $ldaprdn = 'uname';   // DN ou RDN LDAP
  5. $ldappass = 'password'; // Mot de passe associé
  6.  
  7. // Connexion au serveur LDAP
  8. $ldapconn = ldap_connect("ldap.example.com") 
  9.    or die("Impossible de se connecter au serveur LDAP.");  
  10.  
  11. if ($ldapconn) { 
  12.  
  13.    // Connexion au serveur LDAP
  14.    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass); 
  15.  
  16.    // Vérification de l'authentification
  17.    if ($ldapbind) { 
  18.       echo "Connexion LDAP réussie..."; 
  19.    } else { 
  20.       echo "Connexion LDAP échouée..."; 
  21.    }  
  22.  
  23. }  
  24.  
  25. ?> 

Exemple #2 Connexion anonyme à un serveur LDAP

  1. <?php
  2.  
  3. // Connexion anonyme à un serveur LDAP
  4.  
  5. // Connexion au serveur LDAP
  6. $ldapconn = ldap_connect("ldap.example.com") 
  7.    or die("Impossible de se connecter au serveur LDAP.");  
  8.  
  9. if ($ldapconn) { 
  10.  
  11.    // Authentification anonyme
  12.    $ldapbind = ldap_bind($ldapconn); 
  13.  
  14.    if ($ldapbind) { 
  15.       echo "Connexion LDAP anonmye réussie..."; 
  16.    } else { 
  17.       echo "Connexion LDAP anonmye échouée..."; 
  18.    }  
  19.  
  20. }  
  21.  
  22. ?> 

Voir aussi


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique