2011-09-15 74 views
2

我试图在我们公司的Web门户中实现LDAP验证。我可以成功连接到主机,但我似乎无法获得与Active Directory凭据的成功绑定。寻找一些可能出错的帮助。任何帮助,提示或建议将不胜感激。PHP LDAP验证不工作

$username = $_POST['username']; 
$password = $_POST['password']; 

$host = "xxx.xxx.xxx.xxx"; 
$port = "389"; 

$connection = ldap_connect($host, $port) or die("Could not connect to LDAP server."); 
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); 

if ($connection) { 
    $bind = ldap_bind($connection, $username, $password); 
    if ($bind) { 
     echo "LDAP bind successful"; 
    } 
    else { 
     echo "LDAP bind failed"; 
    } 
} 
+1

你检查日志?任何错误,什么**不工作**?你还使用登录DOMAIN \ USERNAME? – Jakub

回答

6

我有同样的问题最近够了,该解决方案是将该域名添加到用户名。

$isAuth = ldap_bind($ldap_conn,$_POST['username'].$ldap_settings['adDomain'], $_POST['password']); 

$ldap_settings['adDomain']是 “@your_domain”

+0

正是我在看到他的绑定时所想的...... – Jakub

+0

这就是解决方案。我有一种感觉,我需要域名,但在我研究的例子中,我没有看到域名附加到用户名。感谢您的及时帮助! – Brett

+0

没有.COM/.NET的域或其他:D – ZiTAL