php bind ldap 範例

$user = "XXXXXX";
$password = "XXXXXX";
$ldapuri = "ldaps://ldap.liho.tw";
$basedn = "dc=liho,dc=tw";
$ldaprdn = "uid=".$user.",ou=people,".$basedn;

// Connecting to LDAP
$ldapconn = ldap_connect($ldapuri, 636)
    or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) {
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $password);

    // verify binding
    if ($ldapbind) {
        echo "LDAP bind successful...";
    } else {
        echo "LDAP bind failed...";
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.