doubo82706 2015-08-17 09:46
浏览 108

我们如何使用php wamp服务器连接和绑定openldap用户

I've installed openldap setup for windows and using these details of ldap user


ip address : http://localhost/
full distinguished name :cn=name,cn=users,dc=mydomain,dc=com,
server name: ldap://server1
pasword : secret
domain : mydomain.com

now i am trying to get username=name given in the code below to be authenticated from ldap server . It is connecting but data bind and search are generating these errors.

Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in C:\wamp\www\ldap authentication\connect.php on line 14


Warning: ldap_search(): supplied argument is not a valid ldap link resource in C:\wamp\www\ldap authentication\connect.php on line 15

I am new at ldap never used before . could anyone tell me where am i wrong or missing something. I am using this code given below.

<?php
$domain = 'mydomain.com';
$username = 'name';
$password = 'secret';
$ldapconfig['host'] = 'ldap://server1';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=mydomain,dc=com';

$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

$dn="cn=users,".$ldapconfig['basedn'];
$bind=ldap_bind($ds, $username .'@' .$domain, $password);
$isITuser = ldap_search($bind,$dn,'(&(objectClass=users)(sAMAccountName=' . $username. '))');
if ($isITuser) {
echo("Login correct");
} else {
echo("Login incorrect");
}
?>
  • 写回答

1条回答 默认 最新

  • dongli5785 2015-08-18 10:52
    关注

    There are two ways to connect to an LDAP-Server using php.

    ldap_connect('ldap.example.com', 389);
    

    or

    ldap_connect('ldap://ldap.example.org:389');
    

    As far as I can see you are trying a mix of both which won't work.

    Personally I like ldap://ldap.example.org:389 as that's the only way to connect to ldaps-secured servers using ldaps://ldap.example.org (you do not need the port if it's the default port)

    评论

报告相同问题?

悬赏问题

  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理