Skip to content

Instantly share code, notes, and snippets.

@tai2
Created April 18, 2013 13:41
Show Gist options
  • Select an option

  • Save tai2/5412758 to your computer and use it in GitHub Desktop.

Select an option

Save tai2/5412758 to your computer and use it in GitHub Desktop.
LDAP authentication.
$conn = ldap_connect($host, $port);
if ($conn) {
echo "ldap connected\n";
if (ldap_bind($conn, $bind_dn, $password)) {
echo "bind suceeded\n";
$search_result = ldap_search($conn, $base_dn, "(&(objectClass=person)(uid={$username}))");
if ($search_result) {
echo "search suceeded\n";
$entries = ldap_get_entries($conn, $search_result);
if (0 < count($entries)) {
$user_dn = $entries[0]['dn'];
if (ldap_bind($conn, $user_dn, $userpwd)) {
echo "user authentication succeeded\n";
} else {
echo "user authentication failed\n";
}
}
}
} else {
echo "bind failed\n";
}
ldap_close($conn);
} else {
echo "connect faild\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment