简体   繁体   English

使用PHP在我的网站上实现LDAP的步骤

[英]Steps to implement LDAP on my website using PHP

任何人都可以让我使用PHP在我的网站上逐步解释LDAP

LDAP support in PHP is not enabled by default. 默认情况下不启用PHP中的LDAP支持。 You will need to use the --with-ldap[=DIR] configuration option when compiling PHP to enable LDAP support. 在编译PHP以启用LDAP支持时,您将需要使用--with-ldap [= DIR]配置选项。 DIR is the LDAP base install directory. DIR是LDAP基本安装目录。 To enable SASL support, be sure --with-ldap-sasl[=DIR] is used, and that sasl.h exists on the system. 要启用SASL支持,请确保使用--with-ldap-sasl [= DIR],并且系统上存在sasl.h。

First make sure you have PHP's LDAP extension installed, as @The MYYN suggests. 首先确保你安装了PHP的LDAP扩展,正如@YYYN建议的那样。 To implement an LDAP-based authentication mechanism I recommend that you use Zend_Auth and its adapter for LDAP . 要实现基于LDAP的身份验证机制,我建议您使用Zend_Auth及其适配器进行LDAP Further operations can be handled with Zend_Ldap . 可以使用Zend_Ldap处理进一步的操作。

It seems that your question is still not answered, because you did not choose an answer. 似乎您的问题仍未得到解答,因为您没有选择答案。

So if you want to know how to authenticate a user, you can do it this way : 因此,如果您想知道如何验证用户,可以这样做:

$userFound = false;

$ds = ldap_connect('my.ldap.com');
if ($ds)
{
    // Anonymous bind
    ldap_bind($ds);
    // Search the DN of the user
    $searchRes = ldap_search($ds, 'ou=people,dc=my_company,dc=com', 'uid=your_user_uid');

    $info = ldap_get_entries($ds, $searchRes);

    // If the search returned at least one result, try to bind to the server
    // using the DN you just get, and the password provided by you user
    if ($info['count'] < 0)
        $userFound = ldap_bind($ds, $info[0]['dn'], $password);

    ldap_close($ds);
}

var_dump($userFound);

Note that, as miku said, you have to install LDAP. 请注意,正如miku所说,您必须安装LDAP。 It is not installed by default. 默认情况下不安装它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM