2014-04-23 81 views
1

如何将PHP连接到活动目录并进行用户身份验证?我已经使用WAMP在本地尝试了LDAP,但到目前为止还没有成功,可能做错了?使用Microsoft Azure活动目录进行PHP用户身份验证

我尝试这样做:

$link = ldap_connect('domain.com'); // Your domain or domain server 
if(! $link) 
{ 
    // Could not connect to server - handle error appropriately 
} 
ldap_set_option($link, LDAP_OPT_PROTOCOL_VERSION, 3); // Recommended for AD 

// Now try to authenticate with credentials provided by user 
if (! ldap_bind($link, '[email protected]', 'SomeSecret')) 
{ 
    // Invalid credentials! Handle error appropriately 
} 
// Bind was successful - continue 

改变域名为我的Active Directory域 “davidecuriosidade.onmicrosoft.com”,但正如我所说的没有成功。我的活动目录是否有配置?

回答

0

当您绑定到LDAP时,您绑定到DN,而不是经典的“用户名”/“密码”组合。

该DN是以LDAP格式编写的,该格式对于Active Directory配置中的设置是唯一的。的

因此而不是[email protected]

它变得更像是:sAMAccountName=myuser,ou=GroupAllowed,dc=domain,dc=com

这是假设在Active Directory安装你有一个“组”(组织单元)名称“GroupAllowed”和“为myuser”是该组中用户的帐户名称。此外,“域”是AD环境的域名,“com”是该域的TLD。

+0

我该如何修改?类似$ user = sAMAccountName = myuser,ou = GroupAllowed,dc = domain,dc = com? – DavideBar

+0

你必须连接字符串。我的建议是: – Danoweb

+0

$ bind ='sAMAccountname ='。 $用户名。 ',ou ='。 $组。 'DC =域,DC = COM'; 或者你也可以使用如下的解决方案: $ bind ='sAMAccountname ='。 $的用户名; $ bind。=',ou ='。 $组; $ bind。=',dc = domain,dc = com'; 然后你打电话会变成: ldap_bind($ link,$ bind,'SomeSecret') – Danoweb

相关问题