如何使用php进行LDAP身份验证使用PHP进行LDAP身份验证
我成功连接了xampp中的ldap服务器。
的LDAP进行绑定成功
,但在做这个代码的一些错误显示
<?php
$ldapBaseDomain = 'ou=employee,dc=domainname';
$ldapServer = 'domainname';
$ldapUsername = 'xxx';
$ldapPassword = 'yyy';
if (!empty($_POST['username']) && !empty($_POST['password'])) {
if (!preg_match('/^[a-zA-Z0-9\-]+$/', $_POST['username'])) {
die('Please enter a valid username');
}
if (!$ldapConnection = @ldap_connect($ldapServer)) {
die('Could not connect to ldap server');
}
if ([email protected]_bind($ldapConnection, $ldapUsername, $ldapPassword)) {
die('Could not bind to ldap server');
}
if (!$ldapSearch = @ldap_search($ldapConnection, $ldapBaseDomain, $_POST['username'])) {
die('Could not complete ldap search');
}
$ldapCount = @ldap_count_entries($ldapConnection, $ldapSearch);
if (!$ldapCount) {
die('account not found');
} else {
if (!$ldapEntry = @ldap_get_entries($ldapConnection, $ldapSearch)) {
die('Could not get ldap entry');
}
$distinguishedName = $ldapEntry[0]['distinguishedname'][0];
if (empty($distinguishedName)) {
die('Account information not found');
}
if([email protected]_bind($ldapConnection, $distinguishedName, $_POST['password'])) {
die('Password Incorrect');
}
echo ' <h1>Logged in successfully</h1>
<h2>User Details</h2>';
echo '<pre>' . print_r($ldapEntry[0], true) . '</pre>';
}
} else {
echo ' <form method="post">
Username: <input name="username"><br>
Password: <input name="password" type="password"><br>
<input type="submit" value="login">
</form>';
}
?>
这是错误显示
Could not complete ldap search
任何提示来解决这个问题
使用“尾-f /无功/日志/ dirsrv /接入” –
SRY我正在期运用窗口广告,这样怎么可以把访问日志从LDAP服务器这是可能的?? – Senthilkumar