任何人都可以让我使用PHP在我的网站上逐步解释LDAP
LDAP support in PHP is not enabled by default. You will need to use the --with-ldap[=DIR] configuration option when compiling PHP to enable LDAP support. DIR is the LDAP base install directory. To enable SASL support, be sure --with-ldap-sasl[=DIR] is used, and that sasl.h exists on the system.
First make sure you have PHP's LDAP extension installed, as @The MYYN suggests. To implement an LDAP-based authentication mechanism I recommend that you use Zend_Auth and its adapter for LDAP . Further operations can be handled with 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. It is not installed by default.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.