Wednesday, September 2, 2009

Simple PHP LDAP Authentification

$username = "username";
$password = "password";
//Connect
$ad = ldap_connect(ldap://ldap.server);
//Set some variables
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
//Bind to the ldap directory
$bd = ldap_bind($ad,$username."@ldap",$password);
if($bd) {
echo "Pass
";
//Search the directory
$result = ldap_search($ad, "OU=org,DC=ldap,DC=server", "(sAMAccountName=".$username.")");
$entries = ldap_get_entries($ad, $result);
echo $entries[0]["displayname"][0]."
";
} else {
echo "Fail
";
}
ldap_close($ad);
?>

1 comment:

onkidkids said...

มีตัวอย่างเปลี่ยน password ไหมครับ